前端开发中,浏览器自带返回键返回指定页面的解决办法

来源:互联网 发布:php 查看网页源代码 编辑:程序博客网 时间:2024/06/06 02:15


在页面中加入以下的代码;

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

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


    $(window).on('popstate', function() {
      var hashLocation = location.hash;
      var hashSplit = hashLocation.split("#!/");
      var hashName = hashSplit[1];


      if (hashName !== '') {
        var hash = window.location.hash;
        if (hash === '') {
          
          location.href="您需要返回的页面"
        }
      }
    });


    window.history.pushState('forward', null, '当前页面');
  }


});
阅读全文
0 0