onunload, on window close but not new page

G

Geoff

I have a javascript function that runs when onunload is triggerd. So
this runs when someone navigates away from the page or closes the
window. I only want the code to run when the window is closed. Anyone
got any ideas?
 
R

Richard Cornford

Geoff said:
I have a javascript function that runs when onunload is triggerd. So
this runs when someone navigates away from the page or closes the
window. I only want the code to run when the window is closed. Anyone
got any ideas?

It cannot be done. Scripts can be written to be aware of page
transitions resulting from navigating using links within a page and drag
and drop operations using URL links/shortcuts (on some browsers), but
navigation resulting form favourites/bookmarks (using the menu or
otherwise), the back button, the history or users typing URLs into the
location bar (or selecting from its the drop-down of recent URLs) cannot
be detected in any way, so they cannot be discriminated from window
closing.

Not all browsers will execute the onunload event when the browser is
closed (there is not much point as there isn't a great deal that a scrip
can do in that context (except maybe attempt to open another window
(which would be near universally unwelcome))).

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top