I know this must be done with javascript. But I am not sure how to do it.
Scenario:
When user close the browser, I will prompt a message whether he/she want to leave comment/feedback or not. If he/she clicks yes, then display(or maybe window.opn/popup), else just close the browser normally.
I tried using onload function, but it does not work in firefox
JS
<script type="text/javascript">
function unloadPage()
{
alert("unload event detected!");
}
</script>
HTML
<body onunload="unload();">
I also tried the onbeforeunload
window.onbeforeunload = test;
function test() {
return "Submit your feedback to us :)";
}
But it appears that, it just prompt like a normal window.alert. It has "Ok" and "Cancel" button. I cant do much from there.
Can we do a check, if the user clicks "OK", we perform/redirect/popup new window, and if user clicks Cancel, we just close the browser?
I always have the compatibility problems, sometimes works in IE but not in FF