2016-12-09 74 views
0

我有一個在線測試,它可以在不停頓的情況下依次運行5個網頁。我希望後退按鈕(如果使用)在測試頁面之前重定向到頁面,防止它被用於循環測試頁面。我認爲歷史API可能是要走的路,並在使用本腳本嘗試:使用歷史記錄API將後退按鈕重定向到特定頁面

var stateObj = { url: "/index.php/toeic_introduction"}; 

// Updates the current history entry timerArray[i][2]. 
window.history.replaceState(stateObj, "","/index.php/toeic_introduction"); 

// Creates a new history entry. 
window.history.pushState(stateObj, "","/index.php/toeic_introduction"); 

這適用於該URL顯示在地址線,但由於所需的後退按鈕不重定向的程度。我甚至不確定是否可以通過這種方式實現對後退按鈕的控制。我曾想過關閉後退按鈕,並在網上瀏覽過,但這個選項似乎相當有問題。我當然會歡迎任何意見或建議。

回答

0

我猜你需要綁定到popState事件,並把你的重定向邏輯有這樣的:

$(document).ready(function() { 
     if (window.history && window.history.pushState) { 
     $(window).on('popstate', function() { 
      // your logic here 
     }); 
     } 
    }); 
+0

這並未沒有工作。測試開始後,地址行不顯示「/index.php/toeic_introduction」。我檢查了一個警報,並且正在訪問該功能。 – RoyS

相關問題