आप:
$("#btnOpenWindow").click(function() {
var done = false;
// Open the window with the empty page
var wnd = window.open("print.html");
// For Chrome and Firefox
$(wnd).load(function() {
injectContent();
});
// For Internet Explorer
$(wnd.document).ready(function() {
injectContent();
});
function injectContent() {
// If the favicon link is loaded in the DOM, the content can be modified
if (!done && $("#favicon", wnd.document).length > 0) {
done = true;
$("head", wnd.document).append("<title>The window title</title>");
$("body", wnd.document).append("<h1>Main title</h1>");
...
}
}
});
तुम सच में नई विंडो के फ़ेविकॉन संशोधित करने की जरूरत है, तो आप एक ही विधि के रूप में ऊपर, निम्न परिवर्तन के साथ उपयोग कर सकते हैं data URI का उपयोग कर एक नई विंडो खोल सकते हैं। यहां कोड है:
<input type="button" value="test" id="TheButton" />
function Start() {
$('#TheButton').click(function() {
var TheNewWindow = window.open("data:text/html;charset=utf8,<html><head><link href='" + window.location.protocol + "//" + window.location.host + "/favicon.ico' rel='icon' type='image/x-icon'><title>Title Works</title></head><body></body></html>");
});
}
$(Start);
और the fiddle।
असल में, data URI आपको यूआरएल में सामग्री निर्दिष्ट करने की अनुमति देता है जैसे कि उसे किसी सर्वर पर जाने की आवश्यकता नहीं है, या, आपके मामले में, "about:blank" संसाधन ब्राउज़र (आवश्यक) के पास है। क्रॉस-उत्पत्ति और अन्य चिंताओं के कारण स्क्रिप्टिंग करते समय "रिक्त" रिक्त हो सकता है।
जैसा कि @ कॉनर्सफ़ान द्वारा नोट किया गया है, यह तकनीक आईई में काम नहीं करती है। जैसा कि in this questionDiego Mijelshon, IE does not allow navigation to a data URI द्वारा इंगित किया गया है, और इस प्रकार इसे एक नई विंडो के लिए यूआरएल के रूप में उपयोग नहीं किया जा सकता है। क्रोम और फ़ायरफ़ॉक्स के हाल के संस्करणों में ठीक काम करने लगता है। मुझे डर है कि मेरे पास सफारी की एक प्रति नहीं है जिस पर परीक्षण किया जाए।
स्रोत
2016-10-28 21:23:42
मुझे इसकी उपयोगिता के बारे में आश्चर्य है, लेकिन यह एक दिलचस्प समस्या है। –
यह एक बिल प्रिंट करने के लिए है। एक नई विंडो है जो HTML प्राप्त करती है ताकि उपयोगकर्ता बिना किसी यूआई के अपने बिल का मुद्रित संस्करण प्राप्त कर सके। – frenchie