Javascript中History对象和Location对象

一、location对象
window. location对象用于获得当前页面的地址 (URL),并把浏览器重定向到新的页面

2、包含的属性:
hash、host(含端口号的主机名)、hostname(不含端口号的主机名)、
href(等价于location.toString()方法)、pathname、port、protocol、search

3、方法:

    

<input type="button" name="" id="btn1" value="assign()" />
		<input type="button" name="" id="btn2" value="reload()" />
		<input type="button" name="" id="btn3" value="replace()" />
		<script type="text/javascript">
			document.getElementById("btn1").onclick=function(){
				location.assign("https://www.baidu.com")
			}
				
			document.getElementById("btn2").onclick=function(){
				location.reload()
			}
			document.getElementById("btn3").onclick=function(){
				location.replace("https://www.baidu.com")
			}


二、history对象

1、go(n):
在用户的历史记录中任意跳转(这里的历史记录不同于浏览器设置中的历史记录,而
是当前标签页的历史记录),n是一个数字,负数表示后退,正数表示前进,例如在
后台中的返回按钮就很能用上

history.go(-1);
2、back()
加载 history 列表中的前一个 URL。

3、forward()
加载 history 列表中的下一个 URL.

4.方法

<input type="button" name="" id="btn1" value="back()" />
		<input type="button" name="" id="btn2" value="forward()" />
		<input type="button" name="" id="btn4" value="打开01.html" />
		<input type="button" name="" id="btn3" value="go" />
		<script type="text/javascript">
			document.getElementById("btn1").onclick=function(){
				history.back()
			}
			document.getElementById("btn4").onclick=function(){
				history.href="01.html"
			}
			document.getElementById("btn1").onclick=function(){
				history.go("https://www.baidu.com")
			}
		</script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值