onunload, on window close but not new page

Discussion in 'Javascript' started by Geoff, Jun 8, 2004.

  1. Geoff

    Geoff Guest

    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?
     
    Geoff, Jun 8, 2004
    #1
    1. Advertisements

  2. 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.
     
    Richard Cornford, Jun 8, 2004
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.