vue禁用浏览器返回功能


 1 // 引入jq
 2 mounted() { // 看好周期
 3     disableBrowserBack();
 4     history.pushState(null, null, document.URL);
 5     if (window.history && window.history.pushState) {
 6         $(window).on('popstate', function () 
 7             window.history.pushState('forward', null, '');
 8             window.history.forward(1);
 9         });
10     }
11     //
12     window.history.pushState('forward', null, '');  //在IE中必须得有这两行
13     window.history.forward(1);
14 },

 

或者提到公共js中

util.js

 1 import "@/xb-share/api/jquery-1.11.3.min.js";
 2  
 3 export const disableBrowserBack = (param) => {
 4     return (function () {
 5         history.pushState(null, null, document.URL);
 6         if (window.history && window.history.pushState) {
 7             $(window).on('popstate', function () {
 8                 window.history.pushState('forward', null, '');
 9                 window.history.forward(1);
10             });
11         }
12         //
13         window.history.pushState('forward', null, '');
14         window.history.forward(1);
15     })()
16 };

页面中引用

1 import {disableBrowserBack} from "../../xb-share/util/util";
2 
3 
4 mounted() {
5     disableBrowserBack()
6 },

就可以了


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM