Skip to content

Instantly share code, notes, and snippets.

@nmorse
Last active March 3, 2016 19:29
Show Gist options
  • Save nmorse/33c685b04bb790e1d498 to your computer and use it in GitHub Desktop.
Save nmorse/33c685b04bb790e1d498 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<body>
<p>Close this window, press F5 or click on the link below to invoke the beforeunload event.</p>
<p>The problem is that we cannot tell the difference between unload and reload</p>
<a href="http://www.google.com">Click here to go to google.com</a>
<div id="count">0</div>
<script>
var count = 0;
var countEle = document.getElementById("count");
window.addEventListener("beforeunload", function(event) {
count++;
countEle.innerHTML = count;
event.returnValue = "By Leaving this page, you will be logged out of your session.";
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment