Skip to content

Instantly share code, notes, and snippets.

@0xPr0xy
Created February 19, 2013 14:41
Show Gist options
  • Select an option

  • Save 0xPr0xy/4986485 to your computer and use it in GitHub Desktop.

Select an option

Save 0xPr0xy/4986485 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script>
function myLoadHandler(evt)
{
if (evt.persisted) {
alert('user returns to page from another tab');
return;
}
alert('loading new page');
}
function myUnloadHandler(evt)
{
if (evt.persisted) {
alert('user goes to new tab');
return;
}
alert('user truly leaves the page');
}
if ("onpagehide" in window) {
window.addEventListener("pageshow", myLoadHandler, false);
window.addEventListener("pagehide", myUnloadHandler, false);
} else {
window.addEventListener("load", myLoadHandler, false);
window.addEventListener("unload", myUnloadHandler, false);
}
</script>
</head>
<body>
<div id="log_id"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment