繁体   English   中英

单击后退按钮重定向到另一个页面

[英]Redirect to another page on clicking the back button

当用户访问我的页面并单击后退按钮时,我想将他们重定向到另一个页面。 我怎样才能做到这一点? 这是在一个简单的 PHP 或 HTML Web 页面中。

如果(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 === '') {
          alert('Back button was pressed.');
            window.location='https://www.google.com/';
            return false;
        }
      }
    });

    window.history.pushState('forward', null, './#forward');
  }

此代码适用于除 Internet Explorer 之外的所有更新的浏览器。 对于 Internet Explorer JSBBQ 库需要实现和修改。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM