JavaScript中window.history 对象包含浏览器历史,history.back()等同于在浏览器点击后退按钮
,history.forward() 等同于在浏览器中点击前进按钮。
history.back() 方法
加载历史列表中前一个 URL,相当于在浏览器中点击后退按钮。
在页面中创建后退按钮:
<html>
<head>
<script>
function goBack() {
window.history.back()
}
</script>
</head>
<body>
<input type="button" value="Back" onclick="goBack()">
</body>
</html>
history forward() 方法
加载历史列表中下一个 URL,这等同于在浏览器中点击前进按钮。
在页面中创建前进按钮:
<html>
<head>
<script>
function goForward() {
window.history.forward()
}
</script>
</head>
<body>
<input type="button" value="Forward" onclick="goForward()">
</body>
</html>