window.loaction和window.history对象

  • location和history都是BOM对象。
  • location对象包含有关当前URL的信息
  • history对象包含用户(在浏览器窗口中)访问的URL
    location对象包含以下属性:
属性描述
hashURL的锚部分
hostURL的主机名和端口
hostnameURL的主机名
href完整的URL
pathnameURL路径名。
portURL服务器使用的端口号
protocolURL协议
searchURL的查询部分(例:get请求的参数部分)

location对象方法:

方法描述
assign()载入一个新的文档
reload()重新加载当前文档
replace()用新的文档替换当前文档

history对象有一个length属性以及以下方法:

方法描述
back()加载 history 列表中的前一个 URL
forward()加载 history 列表中的下一个 URL
go()加载 history 列表中的某个具体页面

调用不同的方法观察参数的变化

<body>
    <button onclick="goAAA()">goAAA</button>
    <button onclick="goBack()">goBack</button>
    <button onclick="forward()">forward</button>
</body>
<script>
    console.log(window.location)
    console.log(window.history)
    function goAAA() {
        window.location.hash = 'hhh'
        console.log(window.location)
        console.log(window.history)
    }
    function goBack() {
        window.history.back()
        console.log(window.location)
        console.log(window.history)
    }
    function forward() {
        window.history.forward()
        console.log(window.location)
        console.log(window.history)
    }
</script>

第一次打印:
在这里插入图片描述
点击goAAA后打印:
在这里插入图片描述
点击goBack后打印:
在这里插入图片描述
点击forward后打印:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

霜叶w

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值