Forum Moderators: open
This is the script I have in the document's head:
<script type="text/javascript">
window.onbeforeunload=function(){
var answer=confirm("You tried to close, reload or move away from this page. You will loose all your data if you did not save or print. \n\n OK - Loose all data. \n Cancel - Return to your document.");
if(!answer) return false;}
</script>
If the user clicks OK, then everything is fine, the action the user does works as expected.
However, if the user clicks CANCEL, then a second confirmation box comes up:
"Are you sure you want to navigate away from this page?
false
Press OK to continue, or Cancel to stay on the current page."
I don't want this second box to appear, I just want if the user clicks on the first CANCEL to be taken back to the page.
I assess this is based on my line "if(!answer) return false;"
What should I put there instead?
Thanks
<script type="text/javascript">
window.onbeforeunload = function () {
return "You tried to close, reload or move away from this page. You will loose all your data if you did not save or print. \n\n OK - Loose all data. \n Cancel - Return to your document.";
}
</script>
[edited by: Fotiman at 5:01 am (utc) on Jan. 24, 2009]