36对象6---history
来源:互联网 发布:钓鱼软件什么意思 编辑:程序博客网 时间:2024/05/29 17:08
History 对象
history对象记录了用户曾经浏览过的页面(URL),并可以实现浏览器前进与后退相似导航的功能。
注意:从窗口被打开的那一刻开始记录,每个浏览器窗口、每个标签页乃至每个框架,都有自己的history对象与特定的window对象关联。
语法:
window.history.[属性|方法]
注意:window可以省略。
History 对象属性
History 对象方法
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>History对象</title></head><script type="text/javascript"> var HL = window.history.length ; document.write(HL);</script><body></body></html>
返回前一个浏览的页面
back()方法,加载 history 列表中的前一个 URL。
语法:
window.history.back();
比如,返回前一个浏览的页面,代码如下:
window.history.back();
注意:等同于点击浏览器的倒退按钮。
back()相当于go(-1),代码如下:
window.history.go(-1);
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>无标题文档</title><script type="text/javascript"> function GoBack() { window.history.back(); }</script></head><body>点击下面的锚点链接,添加历史列表项: <br /> <a href="#target1">第一个锚点</a> <a name="target1"></a> <br /> <a href="#target2">第二个锚点</a> <a name="target2"></a> <br /><br /> 使用下面按钮,实现返回前一个页面: <form> <input type="button" value="返回前一个页面" onclick="GoBack();" /> </form></body></html>
返回下一个浏览的页面
forward()方法,加载 history 列表中的下一个 URL。
如果倒退之后,再想回到倒退之前浏览的页面,则可以使用forward()方法,代码如下:
window.history.forward();
注意:等价点击前进按钮。
forward()相当于go(1),代码如下:
window.history.go(1);
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>无标题文档</title><script type="text/javascript"> function GoForward() { window.history.forward(); }</script></head><body>点击下面的锚点链接,添加历史列表项: <br /> <a href="#target1">第一个锚点</a> <a name="target1"></a> <br /> <a href="#target2">第二个锚点</a> <a name="target2"></a> <br /><br /> 使用下面按钮,实现返回下一个页面: <form> <input type="button" value="返回下一个页面" onclick="GoForward()" /> </form></body></html>
返回浏览历史中的其他页面
go()方法,根据当前所处的页面,加载 history 列表中的某个具体的页面。
语法:
window.history.go(number);
参数:
浏览器中,返回当前页面之前浏览过的第二个历史页面,代码如下:
window.history.go(-2);
注意:和在浏览器中单击两次后退按钮操作一样。
同理,返回当前页面之后浏览过的第三个历史页面,代码如下:
window.history.go(3);
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>无标题文档</title></head> <script type="text/javascript"> function GoBack() { window.history.go(-1); } function GoForward() { window.history.go(1); } </script><body> 点击下面的锚点链接,添加历史列表项: <br /> <a href="#target1">第一个锚点</a> <a name="target1"></a> <br /> <a href="#target2">第二个锚点</a> <a name="target2"></a> <br /><br /> 使用下面按钮,实现返回前或下一个页面: <form> <input type="button" value="返回前一个页面" onclick="GoBack();" /> <input type="button" value="返回下一个页面" onclick="GoForward();" /> </form></body></html>
- 36对象6---history
- history对象
- History 对象
- history对象
- History 对象
- history对象
- History对象
- History对象
- History对象
- History 对象
- History 对象
- history对象
- history对象
- history对象
- History对象
- history对象
- history对象
- History对象,location对象
- javaseday20补充(io 续写 换行 FileWriter 输出个文件)
- hdu1695 GCD
- 适合研发团队的几个项目管理软件对比
- CefSharp.Wpf 添加flash与cookie支持
- 【leetcode】191. Number of 1 Bits(easy)
- 36对象6---history
- sem_init sem_post sem_destroy信号量介绍
- 邮票codevs2033
- 分布式架构设计之Rest API HAL
- hadoop缺少winutils.exe的bug
- Mybatis对于int类型的参数值为0的判断
- SQL Join/Left Join /Right Join...
- 单例模式与多线程
- Cover Flow布局