我正在尝试使用window.open()创建一个然后打印的弹出窗口,但是我遇到问题,IE8挂起后弹出它. 更多详情: 在我的应用程序结束时,我正在尝试打印输出的信息,但我试图在该弹出窗口中包含单独的CSS,jQuery和Javascript.我认为正是这些外部链接导致IE8挂断,但我不确定. 在我测试的所有其他浏览器中发生的事情是弹出窗口,出现打印对话框,打印正常. 在IE8中,窗口弹出,内容出现,CSS似乎加载,但不是Javascript.如果您尝试手动打印(Ctrl P),它将打印而不使用CSS. 我试过这里的例子: Script elements written with document.write in a window opened with window.open are not executed in IE8 on Windows 7
现场演示 如果您想查看实时版本,请访问:http:/// 如果您想要到达打印部分,则必须填写应用程序所需的信息. (第二步,只需填写无线电输入). 要查看完整的javascript:http:///js/scripts.js,您将在其中找到我尝试过的其他方法. 码 将元素传递给函数 $('#actionPrint').live('click', function(event){
printElem('#rc');
}
弹出元素并打印出来. function printElem(elem) {
popup($j(elem).html());
}
function popup(data) {
var mywindow = window.open('', 'printSheet', 'height=500,width=800,scrollbars=1');
mywindow.document.open();
mywindow.document.write('<html><head><title>Roxul Insulation Calculator</title>');
mywindow.document.write('</head><body>');
mywindow.document.write('<div id="rc_logo"><img src="img/roxul-logo.png" alt="roxul-logo" /></div>');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
var c = mywindow.document.createElement("link");
c.rel = "stylesheet";
c.type = "text/css";
c.href = "css/print.css";
mywindow.document.getElementsByTagName("HEAD")[0].appendChild(c);
var s = mywindow.document.createElement("script");
s.type = "text/javascript";
s.src = "js/jquery-1.5.2.min.js";
mywindow.document.getElementsByTagName("HEAD")[0].appendChild(s);
var s2 = mywindow.document.createElement("script");
s2.type = "text/javascript";
s2.src = "js/print.js";
mywindow.document.getElementsByTagName("HEAD")[0].appendChild(s2);
mywindow.print();
return true;
}
解决方法: 我已经解决了我自己的问题,所以希望回答一个人自己的问题并不是坏事. 我的错误不包括mywindow.document.close();在我的功能结束时. 现在看起来如下: mywindow.print();
mywindow.document.close();
return true;
我与其中一位与我合作的开发人员交谈,他说document.close()会释放要打印的资源. 来源:https://www./content-1-437201.html
|