oca hist pushstate ack blank == blog style
JS 监听手机返回键,需要用些前端的 "奇技淫巧"。
核心代码如下:
- if (window.history && window.history.pushState) {
- $(window).on('popstate',
- function() {
- var hashLocation = location.hash;
- var hashSplit = hashLocation.split("#!/");
- var hashName = hashSplit[1];
- if (hashName !== '') {
- var hash = window.location.hash;
- if (hash === '') {
- alert('後退按鈕點擊');
- }
- }
- });
- window.history.pushState('forward', null, '. / #forward');
- }
一个简单的 demo,大家可以看看:
测试 demo
JS 监听手机返回键
来源: http://www.bubuko.com/infodetail-2017395.html