Created
September 22, 2015 02:42
-
-
Save iahu/319f4974eadd6a325299 to your computer and use it in GitHub Desktop.
篡改“浏览器后退按钮”历史纪录 demo
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 lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>demo</title> | |
<style> | |
</style> | |
</head> | |
<body> | |
<p>demo.html</p> | |
</body> | |
</html> |
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 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