top
Loading...
JavaScript Window History

JavaScript Window History


window.history 對象包含瀏覽器的歷史。


Window History

window.history對象在編寫時可不使用 window 這個前綴。

為了保護用戶隱私,對 JavaScript 訪問該對象的方法做出了限製。

一些方法:

  • history.back() - 與在瀏覽器點擊後退按鈕相同
  • history.forward() - 與在瀏覽器中點擊向前按鈕相同

Window History Back

history.back() 方法加載歷史列表中的前一個 URL。

這與在瀏覽器中點擊後退按鈕是相同的:

實例

在頁面上創建後退按鈕:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <head> <script> function goBack() { window.history.back() } </script> </head> <body> <input type="button" value="Back" onclick="goBack()"> </body> </html>

以上代碼輸出為:



Window History Forward

history forward() 方法加載歷史列表中的下一個 URL。

這與在瀏覽器中點擊前進按鈕是相同的:

實例

在頁面上創建一個向前的按鈕:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script> function goForward() { window.history.forward() } </script> </head> <body> <input type="button" value="Forward" onclick="goForward()"> </body> </html>

以上代碼輸出為:



北斗有巢氏 有巢氏北斗