This article mainly introduces in detail the rollback events of js prohibiting browsers, which has certain reference value. Interested friends can refer to
and come directly to the ultimate solution:
I found it after searching a lot of information. This method can eliminate all back movements. Including back actions caused by keyboard, mouse gestures, etc.
<script language="javascript"> //防止页面后退 history.pushState(null, null, document.URL); window.addEventListener('popstate', function () { history.pushState(null, null, document.URL); }); </script>
Now, this method is used in our project. In common browsers, back can be disabled.
Specific example:
$(function(){ if (window.history && window.history.pushState) { history.pushState(null, null, document.URL); window.addEventListener('popstate', forbidBack); } }) /** * 禁止回退按钮 */ function forbidBack(){ appUtils.mobileConfirm("确定放弃重置密码?",function(){//yes window.removeEventListener('popstate',forbidBack); muiwindow.muiwebview({"url":"login.html"}); },function(){//no //防止页面后退 history.pushState(null, null, document.URL); }); }
Students who need to learn js please pay attention to php Chinese website js video tutorial, many js online video tutorials can be watched for free!
The above is the detailed content of How to disable the browser's rollback event using js. For more information, please follow other related articles on the PHP Chinese website!