js- Getting unload to work cross-browser's with a button
-
04-07-2021 - |
Question
Hello 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 Broswers but I can't seem to get them it working together.
The reason for this is I want to clear the information in the broswer 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 broswers are not liking the code in the document. But I want to try other methods for the other broswers I am working with. But I can't seem to get broswer 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.