美文网首页
html 禁止浏览器后退

html 禁止浏览器后退

作者: 矛盾迩 | 来源:发表于2019-10-08 11:29 被阅读0次

//防止页面后退

history.pushState(null, null, document.URL);

window.addEventListener('popstate', function () {

    history.pushState(null, null, document.URL);

});

方法一:

      <script type="text/javascript">

            jQuery(document).ready(function ($) {

                if (window.history && window.history.pushState) {

        $(window).on('popstate', function () {

            window.history.forward(1);

        });

      }

    });

  </script>

  方法二【推荐】:

  $(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);

  })

相关文章

网友评论

      本文标题:html 禁止浏览器后退

      本文链接:https://www.haomeiwen.com/subject/remzectx.html