天天看點

javascript:window下的history對象history對象

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'" target="_blank" rel="external nofollow" >檢視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" target="_blank" rel="external nofollow" >navigator</a>
		<input type="button" value="後退" οnclick="javascript:window.history.back();">
		<input type="button" value="前進" οnclick="javascript:window.history.forward();">
		
	</body>
</html>
           

繼續閱讀