I\'m trying to implement a basic popup window that asks the user if they really want to leave a page, similar to what would happen on this site if I tried to close the windo
window .unload function will help us to execute some javascript while closing the browser or redirecting to any other page. resources: http://api.jquery.com/unload/
At the head:
<head>
...
<script type="text/javascript">
var disabledConfirm_exit=false;
</script>
</head>
In the two links allowed to leave, you can add
onclick="disabledConfirm_exit=true;"
And inside the confirm_exit
function confirm_exit(e) {
if(disabledConfirm_exit) return;
if(!e) e = window.event;
e.cancelBubble = true;
e.returnValue = 'Are you sure you want to leave?';
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
}