Location对象
方法名称 | 说明 |
assign("url") | 加载URL指定的HTML文档 |
reload() | 重新加载当前页 |
replace("url") | 通过加载URL指定的文档来替换当前文档 |
1、assign("url")
格式:location.assign("url")
用法演示:
<body>
<input type="button" value="跳转至百度" id="btn" onclick="a1()">//按钮
<script type="text/javascript">
//按下按钮触发的事件
function a1(){
//跳转至“https://www.baidu.com”
location.assign("https://www.baidu.com")
}
</script>
</body>
2、reload()
格式:location.reload()
用法演示:
<body>
<input type="button" value="刷新" onclick="a1()">//按钮
<script type="text/javascript">
//点击按钮时触发的事件
function a1(){
//重新加载当前页
location.reload()
}
</script>
</body>
3、replace("url")
格式:location.replace("url")
用法演示:
<body>
<input type="button" value="替换当前页" id="btn">
<script type="text/javascript">
document.getElementById("btn").onclick = function() {
location.replace("https://www.baidu.com")
}
</script>
</body>
History对象
方法名称 | 说明 |
back() | 加载History列表中的上一个URL,相当于后退按钮 |
forward() | 加载History列表中的下一个URL,相当于前进按钮 |
go() | 加载History列表中的个URL,或要求浏览器移动指定的页数。go(1)代表前进一页,go(-1)代表后退一页 |
1、back()
格式:history.back()
<body>
<input type="button" value="前进" id="btn" onclick="a1()">
<script type="text/javascript">
function a1(){
history.back()
}
</script>
</body>
2、forward()
格式:history.forward()
<body>
<input type="button" value="后退" id="btn" onclick="a1()">
<script type="text/javascript">
function a1(){
history.forward()
}
</script>
</body>
3、go()
格式:history.go()
<body>
<input type="button" value="前进" onclick="a1()">
<input type="button" value="后退" onclick="a2()">
<script type="text/javascript">
function a1(){
history.go(1)
}
function a2(){
history.go(-1)
}
</script>
</body>