Forum Moderators: open

Message Too Old, No Replies

Open Popup On-unload in Netscape 7.0 or Mozilla 1.1

         

stankb

9:31 pm on Aug 6, 2002 (gmt 0)

10+ Year Member



Hello!

I need to open a new window (using window.open) onUnload and Netscape 7.0 and Mozilla are not displaying them (I think they are just ignoring the call). Is there any way to enable that? Any setting, preference, or any way around it?

I need to perform some unlocking tasks (basically cleanup) when the user clicks the exit button.

I have tried a lot of ways and they all fail. One of the ways that I tried (failed) is below (it works in IE) - just to illustrate:

<html>
<head>
<title>Main Window</title>
<script>
function TheWindowIsBeingClosed()
{ window.open("http://cnn.com");
}
</script>
</head>

<body onunload=TheWindowIsBeingClosed()>

</body>
</html>

Any help appreciated! (This is really important to me.)

Thanks
Stanley

moonbiter

9:46 pm on Aug 6, 2002 (gmt 0)

10+ Year Member



Edit > Preferences > Advanced > Scripts & Plugins > Open Unrequested Windows.

There is a cool Prefbar applet [xulplanet.com] that gives you quick access to these preferences and more.

AFAIK, there is no scripting way around this. This is, IMHO, a good thing.

jdMorgan

10:06 pm on Aug 6, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



stankb,

Another issue to consider is this: What happens if I visit your site with Opera or Mozilla, and
I have specifically disallowed unsolicited pop-ups? What happens if I intentionally disable
JavaScript? Make sure that those objects which need to be unlocked on exit are handled properly
in these cases, even if it means detecting my popup disallow or disabled JS and giving me an error
message before locking them. You probably don't want to lock those objects in the first place if
they can't be unlocked later! As described, you are relying on the user to have JS enabled and
popups allowed - maybe not a good idea, since Mozilla and Opera are touting their ability to reject
popups, and consumers like that option...

Jim

stankb

1:43 pm on Aug 7, 2002 (gmt 0)

10+ Year Member



moonbiter,

I tried that, and it still does not work. Try the script & you'll see it does not open a new window when you close the browse (IE will open it).

Also, how do you install the applet?

Regarding Jim's post, you are right, but this is for our internal application, and those preferences are required.

Thanks anyway,
Stanley

moonbiter

2:36 pm on Aug 7, 2002 (gmt 0)

10+ Year Member



I tried that, and it still does not work. Try the script & you'll see it does not open a new window when you close the browse (IE will open it).

Wierdly, it works for me if I don't close the entire browser but just a tab. Try opening two tabs, and you'll see what I mean. This could be a bug, maybe.

Also, how do you install the applet?

Click on the "Install now" hyperlink (top left, above the screenshot).

[edited by: moonbiter at 3:01 pm (utc) on Aug. 7, 2002]

stankb

3:00 pm on Aug 7, 2002 (gmt 0)

10+ Year Member



moonbiter,

yeah, that's what happens to me. I wonder if that's really a bug (I think it is).

Do you know any Netscape developer newsgroups I can subscribe and maybe tell them about it?

Thanks,
Stan

moonbiter

3:01 pm on Aug 7, 2002 (gmt 0)

10+ Year Member



Hmm. Look at these discussions in Bugzilla:
Basically, they don't support window.open to be called from onunload events, and they consider this to be a feature.

stankb

7:02 pm on Aug 7, 2002 (gmt 0)

10+ Year Member



I submitted a new bug at bugzilla and they say they left that intentionally so I think that there is no way to open a new window on onUnload (waiting for a confirmation from them).

Bug url:
window.open works in onunload in tabbed window but not in normal window [bugzilla.mozilla.org]

tedster

8:04 pm on Aug 7, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



onunload was originally put in javascript for maintenance purposes - garbage collecting as required when a page is left. It was never intended to launch new functionality, although that certainly became the most common usage.

I assume that's the direction that Moz is now taking.

<edited for spelling>

[edited by: tedster at 8:33 pm (utc) on Aug. 7, 2002]

moonbiter

8:29 pm on Aug 7, 2002 (gmt 0)

10+ Year Member



A strict reading of the Gecko DOM Reference [mozilla.org] could be interpreted to mean that the window.onunload event only fires if going into a new document (and not just shutting down the browser).

IMHO, the Mozilla team is doing an incomplete job if they disable window.open() on window.onunload events for closing a window, but not for closing a tab! After all, the stated reason they have left it out is because of abuse by malicious webmasters using "hydra ads" -- but if you browse with many tabs (like I do), then you have a similar problem. <added>I've asked them this on the bug report stankb submitted. Let's see what they say.</added>

stankb

8:37 pm on Aug 7, 2002 (gmt 0)

10+ Year Member



I totally agree with you. They should at least make a preference which you can set on your own (like they do with onLoad event).

stankb

2:51 pm on Aug 8, 2002 (gmt 0)

10+ Year Member



hey guys,

Is there a way to execute some server side code (servlet, asp, etc) when client closes the main browser window?

thanks