Source Code: (back to article)
<body>
<p>Now if you want to exit this page, a confirmation alert will be shown as a result of the <code>beforeunload</code> event.</p>
<script>
window.addEventListener('beforeunload', function(event) {
event.preventDefault();
event.returnValue = true;
})
</script>
</body>