js实现禁止浏览器后退按钮

      function BanBack(ele) {
        //禁止浏览器后退按钮
        if (window.history && window.history.pushState) {
          $(window).on('popstate', function () {
            window.history.pushState('forward', null, '#');
            window.history.forward(1);
            if (ele) {//特殊处理后退url地址
              window.location.href = ele;
            }
          });
        }
        window.history.pushState('forward', null, '#'); //在IE中必须得有这两行
        window.history.forward(1);
      }

你可能感兴趣的:(js实现禁止浏览器后退按钮)