3

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.

user1414745
  • 1,317
  • 6
  • 25
  • 45
  • I dont know if you want a new window or not, because you could perhaps just use a div with an overly etc (that you cant drag or anything). – EricG Nov 30 '12 at 14:09
  • I personally wouldn't worry about this too much. If your popup shows data from a slow process you might show some sort of loading bar or progress indicator while it loads. – Halcyon Nov 30 '12 at 14:10
  • It loads fast, it's a small HTML code. But still, I don't want the page to be loading. Is there an alternative to document.write for writing a whole page? – user1414745 Nov 30 '12 at 14:13

3 Answers3

4

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();
sroes
  • 14,663
  • 1
  • 53
  • 72
  • You should have document.open() before the write(). MDN doc for [document.close()](https://developer.mozilla.org/en-US/docs/DOM/document.close) – epascarello Nov 30 '12 at 14:21
  • @epascarello also from MDN: _Also, an automatic document.open() call happens when document.write() is called after the page has loaded, but that's not defined in the W3C specification. document non-spec'ed parameters to document.open_ – sroes Nov 30 '12 at 14:24
  • Thanks for this answers. Now I use open, write, close, but it still does not work on the server. It works only locally on my laptop. – user1414745 Nov 30 '12 at 14:28
0
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

Anujith
  • 9,370
  • 6
  • 33
  • 48
0

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';
gkiely
  • 2,987
  • 1
  • 23
  • 37