手機移動端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"; //一般用戶按5次返回鍵,就會引起注意而改成按你指定的 關閉按鈕了.
window.location.href = href + "#ggg";
window.location.href = href + "#hhh";
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
原理是在你想禁止的時候把這個 href 地址給重寫個5-6次.
這樣客戶返回來返回去都是當前頁面的不同部分.
不會引起頁面刷新. 重新加載.
一般用戶按5次以後發現沒效果, 基本上就會研究下怎麼回事.
此代碼只適合在頁面中彈出層,遮住了後面的內容後.客戶可能會習慣性的點擊返回按鍵. 這個按鍵我們js是無法控制的.沒有事件. 瀏覽器默認就是返回上一頁.
如果能夠監聽頁面的地址變更事件 用戶體驗會更好.