zoukankan      html  css  js  c++  java
  • 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 },

    就可以了

  • 相关阅读:
    【现在还没补的比赛及题解】
    【刷题中】
    【寒假的待填的坑】
    【python】爬虫实践
    【python】vscode python环境配置
    【spring学习笔记二】Bean
    【spring学习笔记一】Ioc控制反转
    【2018CCPC秦皇岛】
    【2018ICPC沈阳】
    【2018ICPC青岛】
  • 原文地址:https://www.cnblogs.com/xiaozhu-zhu/p/11984056.html
Copyright © 2011-2022 走看看