Javascript window.open和print导致IE8挂起

Pau*_*ham 3 javascript jquery window.open internet-explorer-8

我正在尝试使用window.open()创建一个然后打印的弹出窗口,但是我遇到问题,IE8挂起后弹出它.


更多详情:

在我的应用程序结束时,我正在尝试打印输出的信息,但我试图在该弹出窗口中包含单独的CSS,jQuery和Javascript.我认为正是这些外部链接导致IE8挂断,但我不确定.

在我测试的所有其他浏览器中发生的事情是弹出窗口,出现打印对话框,打印正常.

在IE8中,窗口弹出,内容出现,CSS似乎加载,但不是Javascript.如果您尝试手动打印(Ctrl + P),它将打印而不使用CSS.

我试过这里的例子: 在Windows 7的IE8中不执行用window.open打开的窗口中用document.write编写的脚本元素


现场演示

如果您想查看实时版本,请访问:http://roxulmaterialscalculator.com/ 如果您想要访问打印部分,则必须填写应用程序所需的信息.(第二步,只需填写无线电输入).

要查看完整的javascript:http://roxulmaterialscalculator.com/js/scripts.js,您将找到我尝试过的其他方法.


将元素传递给函数

$('#actionPrint').live('click', function(event){
    printElem('#rc');
}
Run Code Online (Sandbox Code Playgroud)

弹出元素并打印出来.

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;
 }
Run Code Online (Sandbox Code Playgroud)

Pau*_*ham 5

我已经解决了我自己的问题,所以希望回答一个人自己的问题并不是坏事.

我的错误是mywindow.document.close();在我的功能结束时不包括一个.现在看起来如下:

mywindow.print();
mywindow.document.close();
return true;
Run Code Online (Sandbox Code Playgroud)

我与我合作的一位开发人员进行了交谈,并说他document.close()发布了要打印的资源.