我正在嘗試使用window.open()創(chuàng)建一個(gè)然后打印的彈出窗口,但是我遇到問題,IE8掛起后彈出它.
更多詳情:
在我的應(yīng)用程序結(jié)束時(shí),我正在嘗試打印輸出的信息,但我試圖在該彈出窗口中包含單獨(dú)的CSS,jQuery和Javascript.我認(rèn)為正是這些外部鏈接導(dǎo)致IE8掛斷,但我不確定.
在我測試的所有其他瀏覽器中發(fā)生的事情是彈出窗口,出現(xiàn)打印對話框,打印正常.
在IE8中,窗口彈出,內(nèi)容出現(xiàn),CSS似乎加載,但不是Javascript.如果您嘗試手動(dòng)打印(Ctrl P),它將打印而不使用CSS.
現(xiàn)場演示
如果您想查看實(shí)時(shí)版本,請?jiān)L問:http://roxulmaterialscalculator.com/
如果您想要到達(dá)打印部分,則必須填寫應(yīng)用程序所需的信息. (第二步,只需填寫無線電輸入).
要查看完整的javascript:http://roxulmaterialscalculator.com/js/scripts.js,您將在其中找到我嘗試過的其他方法.
碼
將元素傳遞給函數(shù)
$('#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; }
解決方法:
我已經(jīng)解決了我自己的問題,所以希望回答一個(gè)人自己的問題并不是壞事.
我的錯(cuò)誤不包括mywindow.document.close();在我的功能結(jié)束時(shí).
現(xiàn)在看起來如下:
mywindow.print();mywindow.document.close();return true;
我與其中一位與我合作的開發(fā)人員交談,他說document.close()會(huì)釋放要打印的資源.
來源:https://www.icode9.com/content-1-437201.html