history對象
history對象包含用戶(在瀏覽器中)訪問的URL。可以通過window.history訪問。
1.history屬性
length:返回瀏覽器中歷史列表中的URL的數量。
2.history方法
(1)back()方法:加載history列表中的前一個URL.
(2)forward():加載history列表中的後一個URL.
(3)go(n):加載history列表中的某個具體頁面。n>0向後跳轉,n<0向前跳轉。go(1)==forward(),go(-1)==back().
以下是實例,historya.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>history對象</title>
</head>
<body>
<a href="javascript:location.href='historyb.html'">查看history實例</a>
</body>
</html>
以下是實例,history.html<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>history對象</title>
<script type="text/javascript">
for(var Property in window.history)
window.document.write(Property+":"+window.history[Property]+"<br>");
</script>
</head>
<body>
<a href="navigator.html">navigator</a>
<input type="button" value="後退" οnclick="javascript:window.history.back();">
<input type="button" value="前進" οnclick="javascript:window.history.forward();">
</body>
</html>