views:

3164

answers:

4

I'm creating a popup window with no URL source using window.open(). I don't give it a URL because soon I'll want to post a form to it. However, in the meantime I'd like to display a short "Now loading..." message so the user isn't looking at a blank page for the 2-3 seconds it'll take the form post to go through.

I tried adding Javascript that just writes to the popup window's document. That worked great in Firefox and IE 8, but failed with an Access Denied message in IE 6 and 7. Anyone know of a way around this? I would love to be able to a) hard-code some HTML into window.open(), b) learn how to update the popup's DOM in this situation, or c) hear about anything anyone can think of.

Below is the code I'm using to spawn the window:

    var wref = window.open("", winName, "toolbar=1,resizable=1,menubar=1,location=1,status=1,scrollbars=1,width=800,height=600");
    if (wref != null) {
        try {wref.opener = self;} catch (exc) {}

        // while we wait for the handoff form post to go through, display a simple wait message
        $j(wref.document.body).html('Now loading …'); // EPIC FAIL
        wref.focus();
+5  A: 

IE considers "about:blank" to be a insecure URL and it won't let you talk to it. I would create a "Now Loading..." static HTML file and open that instead.

David
+1  A: 

Also note that the winName you supply in IE must NOT have spaces... if so it will fail.

scunliffe
+3  A: 
<a href="#" onclick="return test();">Test</a>
<script type="text/javascript">
function test() {
    window.open('javascript:opener.write(window);', '_name', 'width=200,height=200');
}
function write(w) {
    w.document.write("Hello, World.");
}
</script>

Works in IE 6, 7 & 8, Opera 9.6, Firefox 2 & 3. Does not work in Safari for Windows 3 & 4 or Google Chrome.

When it does work, it results in a pretty ugly URL in the Location box.

If the browser support listed above is acceptable, you can use the solution provided, otherwise I'd do what David said and window.open('Loading.htm' ...) where Loading.htm contains whatever content you want to display (you should probably keep it lightweight otherwise it might take longer to load and render than the form will to POST).

Grant Wagner
A: 

Another workaround is to open an empty "blank.htm" file on your site, then do the document.open() to access it

ken