我想使用window.open()来创建一个弹出,然后打印,但我遇到了问题,IE8挂起后,它弹出了弹出。Javascript 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://roxulmaterialscalculator.com/ 您必须填写该应用程序所需的信息,如果你想达到打印部分。 (在第二步中,只需填写收音机输入即可)。
要查看完整的javascript:http://roxulmaterialscalculator.com/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;
}
我只是猜测,但也许它是悬挂的,因为窗口实际上并没有加载之前,你告诉它打印。试试这个弹出窗口:'
'并跳过在头部加载这些js文件(如果你只是在打印,我怀疑你需要在jQuery中弹出任何东西) – Flambino