Last active
March 3, 2016 19:29
-
-
Save nmorse/33c685b04bb790e1d498 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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