Home > Web Front-end > JS Tutorial > body text

How to disable the browser's rollback event using js

零下一度
Release: 2018-05-10 15:33:39
Original
2602 people have browsed it

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(&#39;popstate&#39;, function () {
   history.pushState(null, null, document.URL);
 });
</script>
Copy after login

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(&#39;popstate&#39;, forbidBack);
 }
})
/**
 * 禁止回退按钮
 */
function forbidBack(){
 appUtils.mobileConfirm("确定放弃重置密码?",function(){//yes
  window.removeEventListener(&#39;popstate&#39;,forbidBack);
  muiwindow.muiwebview({"url":"login.html"});
 },function(){//no
  //防止页面后退
  history.pushState(null, null, document.URL);
 });
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template