Skip to content

Instantly share code, notes, and snippets.

@iahu
Created September 22, 2015 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iahu/319f4974eadd6a325299 to your computer and use it in GitHub Desktop.
Save iahu/319f4974eadd6a325299 to your computer and use it in GitHub Desktop.
篡改“浏览器后退按钮”历史纪录 demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>demo</title>
<style>
</style>
</head>
<body>
<p>demo.html</p>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
<style>
.test { font: 18px/1.5 微软雅黑, 黑体,arial, sans-serif;}
</style>
</head>
<body>
<h3 class="test">篡改“浏览器后退按钮”历史纪录 demo</h3>
<p>点击下面链接几次后,再点击浏览器后退按钮试试</p>
<a href="#!1">hash #!1</a>
<a href="#!2">hash #!2</a>
<script>
var inPage = false;
document.body.addEventListener('mouseover', function(e) {
inPage = true;
});
document.body.addEventListener('mouseenter', function(e) {
inPage = true;
});
document.body.addEventListener('mouseleave', function(e) {
inPage = false;
});
window.addEventListener('popstate', function(e) {
if ( !inPage && /#!\d/g.test( location.hash ) ) {
location.replace('demo.html');
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment