javascriptdom-eventswindow.onunload

Getting unload to work cross-browser's with a button


I am wondering if I can have the unload method in Javascript do a button.click; or a document.getElementById('target').click(), now I am working on different methods for different browsers but I can't seem to get them it working together.

The reason for this is I want to clear the information in the browser but I can't seem to get the unload method to work right. But I don't even know if the unload method is capable of doing a button.click or a document.getElementById('target').click(); Is there like a list of things this method can or cannot do? Here is the code I am trying to get working:

  window.onunload=leave;

     function leave() {
        
    // For Internet Explorer only. 
    if (navigator.appName == "Explorer"){
    document.getElementById('kioskform:broswerCloseSubmit').click();
    }
    
    // For Chrome only
    if (navigator.appName == "Chrome"){
    // add code for Chrome to use.
    }
    
    // for Safari only
    if (navigator.appName == "Safari"){
    // add code for Safari to use
    }
    
    // for Firefox only 
    if (navigator.appName == "Firefox"){
    // add code for Firefox to use
    }
    
}

So far the only thing working is IE but the other web browsers are not liking the code in the document. But I want to try other methods for the other browsers I am working with. But I can't seem to get browser detection to work at all, any idea's or suggestions or advice is greatly appreciated thank you.


Solution

  • Some browsers (Chrome / FF) does not support the window.onunload method.

    See: http://bugs.jquery.com/ticket/10509