手机移动端web 禁止手机返回功能的最好方法
虽然很变态,但是很有效.
var href = window.location.href
window.location.href = href + "#aaa"
window.location.href = href + "#bbb"
window.location.href = href + "#ccc"
window.location.href = href + "#ddd"
window.location.href = href + "#eee"
window.location.href = href + "#fff"
window.location.href = href + "#ggg"
window.location.href = href + "#hhh"
原理是在你想禁止的时候把这个 href 地址给重写个5-6次.
这样客户返回来返回去都是当前页面的不同部分.
不会引起页面刷新. 重新加载.
一般用户按5次以后发现没效果, 基本上就会研究下怎么回事.
此代码只适合在页面中弹出层,遮住了后面的内容后.客户可能会习惯性的点击返回按键. 这个按键我们js是无法控制的.没有事件. 浏览器默认就是返回上一页.
如果能够监听页面的地址变更事件 用户体验会更好.