亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

JavaScript 窗口歷史記錄

History 對象

JavaScript History 對象用于記錄操作瀏覽器的訪問歷史。History 對象是 window 對象的一部分,可通過 window.history 屬性對其進行訪問。

提示:History 對象的有效作用范圍都是指當前窗口。

History 對象 length 屬性

History 對象有唯一的一個 length 屬性,用于得到瀏覽器訪問歷史記錄中的 URL 數(shù)量。例子如下:

<!DOCTYPE html>
<html>
<head> 
<meta charset="utf-8"> 
<title>php中文網(php.cn)</title> 
<script type="text/javascript">
document.write(history.length);
</script>
</head>
<body>
</body>
</html>

說明

該例子輸出的結果取決于當前頁面的瀏覽記錄,如果是新窗口打開該例子,IE 瀏覽器會輸出 0(即從 0 開始計算),而 Firefox、Chrome 等瀏覽器則會輸出 1。

back() 方法

back() 方法用于返回前一個瀏覽頁面(如果存在),其效果相當于點擊瀏覽器的返回按鈕或者調用 history.go(-1)。以下是常用的返回上一頁提示:

<a href="javascript:window.history.back()" />返回上一頁</a>

<html>
<head>
<script>
function goBack()
  {
  window.history.back()
  }
</script>
</head>
<body>
<input type="button" value="Back" onclick="goBack()">
</body>
</html>


forward() 方法

back() 方法用于前往下一個瀏覽頁面(如果存在),其效果相當于點擊瀏覽器的前進按鈕或者調用 history.go(1)。例子:

<a href="javascript:window.history.forward()" />前往下一頁</a>

<html>
<head>
<script>
function goForward()
  {
  window.history.forward()
  }
</script>
</head>
<body>
<input type="button" value="Forward" onclick="goForward()">
</body>
</html>

注意: back方法和forward方法需要瀏覽器存在歷史記錄的情況下才能顯示。


繼續(xù)學習
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(php.cn)</title> <script type="text/javascript"> document.write(history.length); </script> </head> <body> </body> </html>
提交重置代碼