Javascript window.open和print导致IE8挂起
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Javascript window.open和print导致IE8挂起,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2229字,纯文字阅读大概需要4分钟。
内容图文
![Javascript window.open和print导致IE8挂起](/upload/InfoBanner/zyjiaocheng/720/d7700bfbbba547ef8493ec0a46b2b049.jpg)
我正在尝试使用window.open()创建一个然后打印的弹出窗口,但是我遇到问题,IE8挂起后弹出它.
更多详情:
在我的应用程序结束时,我正在尝试打印输出的信息,但我试图在该弹出窗口中包含单独的CSS,jQuery和Javascript.我认为正是这些外部链接导致IE8挂断,但我不确定.
在我测试的所有其他浏览器中发生的事情是弹出窗口,出现打印对话框,打印正常.
在IE8中,窗口弹出,内容出现,CSS似乎加载,但不是Javascript.如果您尝试手动打印(Ctrl P),它将打印而不使用CSS.
现场演示
如果您想查看实时版本,请访问: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;
}
解决方法:
我已经解决了我自己的问题,所以希望回答一个人自己的问题并不是坏事.
我的错误不包括mywindow.document.close();在我的功能结束时.
现在看起来如下:
mywindow.print();
mywindow.document.close();
return true;
我与其中一位与我合作的开发人员交谈,他说document.close()会释放要打印的资源.
内容总结
以上是互联网集市为您收集整理的Javascript window.open和print导致IE8挂起全部内容,希望文章能够帮你解决Javascript window.open和print导致IE8挂起所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。