2011-07-24 45 views
1

我有一個嵌入隨機站點的小部件。當用戶點擊我呼叫服務器更新點擊發生,服務器返回重定向到正確的頁面。問題是瀏覽器的後退按鈕不再有效。後退按鈕無法在JavaScript重定向後工作

我使用location.href作爲重定向。

我試過location.replace,它保留了後退按鈕,但它轉到頁面之前的頁面中點擊小部件(它用新頁面替換它)。

如何在向服務器報告之後執行頁面切換並仍然允許後退按鈕工作?

回答

4

您無法返回到自動重定向的頁面。這只是一個折返的按鈕和一個沮喪的用戶。

User goes to page A. 
User clicks on link to page B. 
Page B automatically redirects to page C with window.location. 
User hits back button and momentarily goes back to page B. 
Page B automatically redirects to page C with window.location. 
User hits back button and momentarily goes back to page B. 
Page B automatically redirects to page C with window.location. 
User is sad. 

顯然這是行不通的。它具有這樣的替代工作:

User goes to page A. 
User clicks on link to page B. 
Page B automatically redirects to page C with window.location.replace(). 
User hits back button and goes back to page A. 
User is happy. 

您必須window.location.replace()如果你想後退按鈕的工作自動重定向。

+0

不錯的概念。 它對我來說並不理想,因爲我需要實現頁面B並將所有信息發送給服務器端報告。由於它不在我自己的網站上的小部件是一個問題。但如果沒有更好的選擇出現,這可能是一個解決方法。 – Nir

+0

聽起來很奇怪。你說你必須在頁面B中放置大量信息,但用戶會自動從頁面B重定向。我想我不明白爲什麼用戶需要看到頁面B? – jfriend00

相關問題