I am writing for some adivce on a javascript I made for a xhtml page. I got it to mostly work on IE, FF and chrome (Safari still giving me some grief but thats another subject.) The problem I am having is that IE would run the beforeunload event even when someone is submitting a form which is not something i want to happen because the beforeunload script would cause the information to be reseted. It even does it when I press F5 which isn’t something I want either. Now FF and Chrome aren’t having that problem when the form is submitted don’t know why though. Here is the code I have written so far.
<script type="text/javascript">
window.onbeforeunload = function() {
var hiddenBtn = document.getElementById("kioskform:broswerCloseSubmit");
return hiddenBtn.click();
} </script>
Just wondering how to go about this any advice is very appreciated thank you.
Define a html hidden variable. Assign a value to when the user submits the form. Then in your unload function, check that hidden variable. If it’s populated with whatever value, then leave the function.