Skip to content

Instantly share code, notes, and snippets.

@sriannamalai
Last active December 22, 2015 11:59
Show Gist options
  • Save sriannamalai/6469761 to your computer and use it in GitHub Desktop.
Save sriannamalai/6469761 to your computer and use it in GitHub Desktop.
Code to open a URL upon exiting from the currently visited site in the Browser
<html>
<head>
<script language="javascript">
var isExit = true;
</script>
</head>
<body>
<a href="some-other-link-inside-your-site" onclick="isExit = false;">some other link inside your site</a>
<script language="javascript">
// Open an URL as the Window is closed
window.onbeforeunload = function() {
if (isExit) window.open("http://test.com");
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment