简体   繁体   中英

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

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.

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();
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

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';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM