JavaScript Window History
window.history 对象包含浏览器历史记录。
Window History
window.history 对象可以不带 window 前缀。
为了保护用户的隐私,JavaScript 访问此对象的方式受到限制。
一些方法:
history.back() - 与在浏览器中单击后退相同
history.forward() - 与在浏览器中单击前进相同
Window History后退
history.back() 方法加载历史记录列表中的上一个 URL。
这与在浏览器中单击后退按钮相同。
示例
在页面上创建后退按钮:
<html>
<head>
<script>
function goBack() {
window.history.back()
}
</script>
</head>
<body>
<input type="button" value="Back" onclick="goBack()">
</body>
</html>
上述代码的输出将是:
Window History前进
history.forward() 方法加载历史记录列表中的下一个 URL。
这与单击浏览器中的前进按钮相同。
示例
在页面上创建前进按钮:
<html>
<head>
<script>
function goForward() {
window.history.forward()
}
</script>
</head>
<body>
<input type="button" value="Forward" onclick="goForward()">
</body>
</html>
上述代码的输出将是:
总结
本文介绍了的使用,如有问题欢迎私信和评论