Testing when a window is about to close

They have: 19 posts

Joined: Feb 2000

Is there any way you can test for when someone has tried to close a browser so that you can run some JavaScript say to do something before it closes. I tried on unLoad() but this just executed script every time the page changed.

Thanks alot

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi david,

Other than through cgi, no. And even then, it might be too late. The best you can do is test if they are leaving through a link from your page.
Why would you want to anyway? Hit them with a banner? Bad idea, many people won't return if they're forced to read ads. Hit them with an ezine plug? Do it with onLoad (it's almost acceptable nowadays).
btw: I hope 'unLoad' was a typo; should have been 'onUnload'
Vinny

Where the world once stood
the blades of grass cut me still

They have: 184 posts

Joined: Jun 2000

Want to see a known offender?

http://www.freefever.com

Good site, the owner just blatantly spams you, though.

They have: 19 posts

Joined: Feb 2000

Thanks for your responses, in answer to Vinny, the reason for me needing this is that, on my site they open up a popup window which is basically just another browser, however when they close the parent window I want this "popup" window to disappear also, cleaning up so to speak.

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi,

where childWin is the name of the spawned window. You might also try closing the window from within itself with a setTimeout. If no key action, no mouse, no focus, close()

Vinny

Where the world once stood
the blades of grass cut me still

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.