OnUnLoad

Discussion in 'Javascript' started by Simon Wigzell, Sep 26, 2003.

  1. I'm using OnUnLoad in my body statement to redirect to a function to clean
    things up if someone exits a form by closing it from outside the webpage
    code - e.g. by not using the cancel or save and exit buttons I have supplied
    but by clicking on the browser window top right X or closing it by clicking
    with the right mouse button on the tray icon for the window. Unfortunately
    it is also triggered by a refresh, which my web page does as part of it's
    functionality. Is there not a way of only trapping "improper" exiting of a
    web page? Thanks.
     
    Simon Wigzell, Sep 26, 2003
    #1
    1. Advertisements

  2. Simon Wigzell

    Ivo Guest

    Depends on why and when you refresh. Whether or not it is predictable enough
    to set a variable onbeforerefresh and don't set it otherwise. Then make the
    unload function check that variable before doing its thing.
    Ivo
     
    Ivo, Sep 26, 2003
    #2
    1. Advertisements

  3. Simon Wigzell

    VK Guest

    On load:
    ....
    if (Explorer) {self.attachEvent('onunload',sayByeBye);}
    else if (Netscape) {self.addEventListener('onunload',sayByeBye,true);}
    else {/* just forget it */}
    ....

    Then supposing you know when you want to refresh your site (and you should
    for sure!):

    Before refresh:
    if (Explorer) {self.detachEvent('onunload',sayByeBye);}
    else if (Netscape) {self.removeEventListener('onunload',sayByeBye,true);}
    else {/* just forget it again*/}
    Now do your refresh...
     
    VK, Sep 26, 2003
    #3
    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.