I'm using this script to prevent reload and back button navigation of a page to inform the user of if he/she leaves, changes done will be lost.
In Firefox, the problem only seem to occure when hitting the back button. The alert dialog box is shown and just keeps on looping back up whether you press "stay" or "leave", and you must force close Firefox.
Is there a better script for this, that actually works in FF?
window.onbeforeunload = function (e) {
e = e || window.event;
if (e) {
e.returnValue = message;
}
return message;
};
This code works for me in firefox and Chrome:
<script type="text/javascript">
window.onbeforeunload = confirmExit;
function confirmExit()
{
return "Are you sure you want to leave?";
}
</script>