what should I use instead of document.write for a popup

邮差的信 提交于 2019-12-04 04:25:56

问题


in my web page, I am opening a popup window and generate the HTML for the popup using JavaScript/jQuery:

var site="<html> ............. </html>";
var popupWindow = window.open("","","menubar=0,scrollbars=0");
popupWindow.document.write(site);

The problem is, that the popup window shows "reading" in the status bar. What should I use instead of document.write()?

EDIT:

document.close();

should do the work, thanks. Unfortunately, my framework may be interfering, so it's not working for me in FF. IE works.


回答1:


You have to close the document when you'r done writing:

var site="<html> ............. </html>";
var popupWindow = window.open("","","menubar=0,scrollbars=0");
popupWindow.document.write(site);
popupWindow.document.close();



回答2:


popupWindow.document.close();

Adding this to the end will solve the issue. I have found it here before : http://p2p.wrox.com/javascript-how/36703-javascript-popup-keeps-loading.html




回答3:


You should use jQuery's append()

var win = window.open();
    var popup = win.document.body;
    $(popup).append('site html');

Or innerHTML

var popup = window.open();
popup.document.body.innerHTML = 'site data here';


来源:https://stackoverflow.com/questions/13646800/what-should-i-use-instead-of-document-write-for-a-popup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!