history对象
history对象,也叫历史清单对象,在网页设计中,它负责保存窗口或框架在某个时间段内的URL
<input type="button" id="btn" value="打开2.html" />
<script type="text/javascript">
document.getElementById("btn").onclick=function(){
location.href="2.html"
}
</script>
<input type="button" id="btn1" value="back" />
<input type="button" id="btn2" value="打开3.html" />
<input type="button" id="btn3" value="forward()" />
<input type="button" id="btn4" value="go" />
<script type="text/javascript">
document.getElementById("btn1").onclick=function(){
history.back()
}
document.getElementById("btn2").onclick=function(){
location.href="3.html"
}
document.getElementById("btn3").onclick=function(){
history.forward()
}
document.getElementById("btn4").onclick=function(){
history.go(1)
}
</script>
<input type="button" id="btn1" value="back" />
<input type="button" id="btn2" value="打开1.html" />
<input type="button" id="btn3" value="forward()" />
<input type="button" id="btn4" value="go" />
<script type="text/javascript">
document.getElementById("btn1").onclick=function(){
history.back()
}
document.getElementById("btn2").onclick=function(){
location.href="1.html"
}
</script>
location对象
Location 对象包含有关当前 URL 的信息。
Location 对象是 window 对象的一部分,可通过 window.location.xxx 格式的相关属性对其进行访问。
<input type="button" id="btn1" value="assign()" />
<input type="button" id="btn2" value="reload()" />
<input type="button" id="btn3" value="replace()" />
<script type="text/javascript">
console.log(location.host);
console.log(location.hostname);
console.log(location.href);
document.getElementById("btn1").onclick=function(){
location.assign("https://blog.csdn.net/weixin_70647138")
}
document.getElementById("btn2").onclick=function(){
location.reload()
}
document.getElementById("btn3").onclick=function(){
location.replace("https://blog.csdn.net/weixin_70647138")
}
</script>