Skip to content

Instantly share code, notes, and snippets.

@zapthedingbat
Last active February 17, 2016 18:04
Show Gist options
  • Save zapthedingbat/1ff548931e3b81063c32 to your computer and use it in GitHub Desktop.
Save zapthedingbat/1ff548931e3b81063c32 to your computer and use it in GitHub Desktop.
Chrome Unload Back Bug
<!DOCTYPE html>
<html>
<head>
<script>
window.addEventListener('unload', function(){
var origionalUrl = location.href;
var newUrl = origionalUrl.replace('#.*$', '') + '#nope';
console.log('cancel navigation', newUrl);
window.location.replace(newUrl);
window.location.replace(origionalUrl);
});
</script>
</head>
<body>
<h1>Back Bug</h1>
<p>
Click back to leave this page.
</p>
<p>
<a href="http://www.example.com">Somewhere Else</a>
</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment