簡體   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