简体   繁体   English

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

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

When a user visits my page and clicks on the back button I want to redirect them to another page.当用户访问我的页面并单击后退按钮时,我想将他们重定向到另一个页面。 How can I do this?我怎样才能做到这一点? This is in a simple PHP or HTML Web page.这是在一个简单的 PHP 或 HTML Web 页面中。

if (window.history && window.history.pushState) {如果(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');
  }

This code works on all updated browsers except internet explorer.此代码适用于除 Internet Explorer 之外的所有更新的浏览器。 For internet explorer JSBBQ library needs to be implemented and modified.对于 Internet Explorer JSBBQ 库需要实现和修改。

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

相关问题 单击“后退”按钮并登陆到具有超时重定向的页面上 - Clicking the back button and landing on a page with a timeout redirect to the same page 单击子导航标题上的按钮时如何重定向到另一个页面? - How to redirect to another page when clicking the button on a subnav header? 单击到jQuery弹出按钮时重定向到另一个页面 - redirect to another page when clicking to jquery popup button 在特定页面上单击浏览器后退按钮后如何重定向到主页 - How to redirect to home page after clicking browser back button, when on a particular page 单击灯箱上的关闭按钮时,重定向到另一个 url - On clicking close button on a lightbox redirect to another url 通过单击后退按钮重新加载上一页 - Reload the previous page by clicking the back button 单击确认对话框的“取消”按钮时页面重定向 - Page redirect on clicking of “Cancel” button of a confirm dialogue 单击确定按钮后,请进行页面重定向 - After clicking ok button, do page redirect 单击一行必须将页面重定向到另一个URL - Clicking on a row must redirect the page to another URL 如何通过单击iframe中的按钮将用户重定向到另一个页面 - How do I redirect user to another page from clicking a button that's in an iframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM