window.history 对象在编写时可不使用 window 这个前缀。

为了保护用户隐私,对 JavaScript 访问该对象的方法做出了限制。

一些方法:

  • history.back() - 与在浏览器点击后退按钮相同
  • history.forward() - 与在浏览器中点击按钮向前相同

Window History Back

history.back() 方法加载历史列表中的前一个 URL。

这与在浏览器中点击后退按钮是相同的

Window History Forward

history forward() 方法加载历史列表中的下一个 URL。

这与在浏览器中点击前进按钮是相同的

Window History Forward

history forward() 方法加载历史列表中的下一个 URL。

这与在浏览器中点击前进按钮是相同的:

实例:

<html>
<button name="back" value="后退" onclick="goBack()">后退</button>
<button name="forward" value="前进" onclick="goForward()">前进</button>
<script type="text/javascript">
function goBack(){
        history.back();         
}
function goForward(){
        history.forward();      
}       
</script>
</html>

其他方法:

history.go(0);//刷新当前页面
//以下是要在浏览器中有历史记录的,否则不会有效果.
history.go(1);//前进一页
history.go(-1);//后退一页
history.go(-2);//后退两页
history.length;//当前窗口包含的历史记录条数

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-20
  • 2021-11-23
  • 2022-01-30
  • 2021-11-26
猜你喜欢
  • 2021-11-17
  • 2021-10-25
  • 2022-12-23
  • 2021-07-01
  • 2022-12-23
  • 2022-01-04
相关资源
相似解决方案