vue中禁止浏览器刷新和鼠标右键事件

2020-09-17  本文已影响0人  Binary_r
created() {
    this.stopF5Refresh();
  },

stopF5Refresh() {
      document.onkeydown = function(e) {
        var evt = window.event || e;
        var code = evt.keyCode || evt.which;
        //屏蔽F1---F12
        if (code > 111 && code < 124) {
          if (evt.preventDefault) {
            evt.preventDefault();
          } else {
            evt.keyCode = 0;
            evt.returnValue = false;
          }
        }
      };
      //禁止鼠标右键菜单
      document.oncontextmenu = function(e) {
        return false;
      };
      //阻止后退的所有动作,包括 键盘、鼠标手势等产生的后退动作。
      history.pushState(null, null, window.location.href);
      window.addEventListener("popstate", function() {
        history.pushState(null, null, window.location.href);
      });
    },
上一篇 下一篇

猜你喜欢

热点阅读