Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to capture the browser close event in NN 6.0 & IE 4.0+

Status
Not open for further replies.

alpot

Programmer
Mar 8, 2001
8
US
Is there a clean way to capture the browser closing event in NN 6.0 & IE 4.0+. I tried the "onunload()" method which
also gets called when the user unloads a page and not closes the browser. There is no way to differentiate between the two events. Why dosen't Javascript have an onClose() event that will trap browser closing?
 
Check whether it exists or not - or use the window.closed property - which returns true if closed.


b[sup]2[/sup] - benbiddington@surf4nix.com
 
function check() {
if (window.closed) window.open("}

<body onunload=&quot;check();&quot;>

Closing the browser did not open a new window with Yahoo.com?

Whats going on
 
Do you mean the existing window - not one opened by you using JavaScript? When these are closed - the client is prompted with a &quot;do you want to close?&quot; message. The irony is, for the code above to work the window itself needs to be closed for the function to run! The only practical way to use the closed property - is to check if someother window is open or closed - you could try the onbeforeunload habdler - to open a new window, if there isn't one already:

You can obtain a reference to an already opened window (via JavaScript) by calling the open method with no page specified. Something like this.
self.open('','','')


So are you trying to pop up a window after someone has decided to quit Internet Explorer? Unless you have another window open somewhere, there is no way to spawn a new window. It seems you are trying to go against the wishes of the client.

I would be interested in your objective for this. ;-)


b[sup]2[/sup] - benbiddington@surf4nix.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top