JavaScript Window History

Objek window.history mengandung sejarah pelayar.

Sejarah Tetingkap

window.history Objek dapat ditulis tanpa window.

Untuk melindungi privasi pengguna, akses JavaScript ke objek ini ada batasan.

Beberapa Metode:

  • history.back() - Serupa dengan menekan tombol kembali di pelayar
  • history.forward() - Serupa dengan menekan tombol maju di pelayar

Kembali Sejarah Tetingkap

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 Forward

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

这等同于在浏览器中点击前进按钮。

实例

在页面中创建前进按钮:

<html>
<head>
<script>
function goForward() {
    window.history.forward()
 }
</script>
</head>
<body>
<input type="button" value="Forward" onclick="goForward()">
</body>
</html>

以上代码的输出将是: