我正在尝试打开一个新
窗口并打印
内容。
var parentHeader= $("head").html();
var parentDivContent = $("#printer_data_1").html();
var newW= window.open("", "", "scrollbars=1,width=200,height=200");
newW.document.write('<html><head><title>Title</title>'+parentHeader+'</head>');
newW.document.write('<body><div>');
newW.document.write(parentDivContent );
newW.document.write('</div></body></html>');
newW.document.close();
newW.print();
newW.close();
当我尝试运行上面的 code
时,它在 IE8
中挂起,当我评论下面的行时......它有效。
newW.document.write('<html><head><title>Title</title>'+parentHeader+'</head>');
我希望在新窗口的头部部分加载全部内容和样式。
最佳答案
want the entire content, styles to be loaded in the head section of new window
尝试将 newW
的 html
编译成单个字符串,包括 head
html
parentHeader
;在调用 window.open()
的第二个参数中为 newW
设置 name
引用;使用单个 html
字符串作为参数调用 document.write
var parentHeader= $("head").html();
var parentDivContent = $("#printer_data_1").html();
var newW= window.open("", "newW", "scrollbars=1,width=200,height=200");
var html = "<html>"
+ parentHeader // `parentHeader` `head` `html`
+ "<body><div>"
+ parentDivContent
+ "</div></body></html>"
newW.document.write(html);
newW.document.close();
newW.print();
newW.close();
关于javascript - window.print() 在 Internet Explorer 中挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31215457/