包含用户(在浏览器窗口中)访问过的 URL。
History 对象是 window 对象的一部分,可通过 window.history 属性对其进行访问。
声明了浏览器历史列表中的元素数量
history.length
document.write("历史列表中URL的数量: " + history.length);可加载历史列表中的前一个 URL(如果存在)
调用该方法的效果等价于点击后退按钮或调用 history.go(-1)。
history.back()
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>zsh</title> <script> function goBack(){ window.history.back() document.write(document.body.innerHTML +="历史列表中URL的数量: " + history.length); } </script> </head> <body> <input type="button" value="返回" onclick="goBack()"> <a href="#" target="_self">点我点我</a> </body> </html>可加载历史列表中的下一个 URL(如果存在)
调用该方法的效果等价于点击前进按钮或调用 history.go(1)。
history.forward()
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>zsh</title> <script> function goBack(){ window.history.back() document.write(document.body.innerHTML +="历史列表中URL的数量: " + history.length); goBack = function(){ window.history.forward(); document.write("现在前进了"); } } </script> </head> <body> <input type="button" value="返回" onclick="goBack()"> <a href="#" target="_self">点我点我</a> </body> </html>可加载历史列表中的某个具体的页面
该参数可以是数字,使用的是要访问的 URL 在 History 的 URL 列表中的相对位置。(-1上一个页面,1前进一个页面)。或一个字符串,字符串必须是局部或完整的URL,该函数会去匹配字符串的第一个URL。
history.go(number|URL)
文档内容出自 W3cSchool和菜鸟教程, 如需查看更详细的有关内容 请登录 http://www.w3school.com.cn/ 和 http://www.runoob.com/