丶红丝错千重
侠客
侠客
  • 最后登录2021-09-26
  • 发帖数10
阅读:5631回复:0

[javascript]禁止网页前进后退

楼主#
更多 发布于:2020-03-11 13:01
有时候需要用到禁止网页的前进后退

代码如下:
jQuery(document).ready(function () {
                 if (window.history && window.history.pushState) {
                     $(window).on('popstate', function () {
               /// 当点击浏览器的 后退和前进按钮 时才会被触发, 
                         window.history.pushState('forward', null, ''); 
                         window.history.forward(1);
                     });
                 }
         //
                 window.history.pushState('forward', null, '');  //在IE中必须得有这两行
                 window.history.forward(1);
             });
游客


返回顶部

公众号

公众号