javascript:window下的history对象

本文详细介绍了JavaScript中的history对象,包括其属性和方法。如length属性可获取历史记录条数,back()、forward()及go(n)方法则分别用于浏览器历史记录的后退、前进和指定位置跳转。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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="后退" onclick="javascript:window.history.back();">
		<input type="button" value="前进" onclick="javascript:window.history.forward();">
		
	</body>
</html>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值