Web履歴API
Web History APIは、windows.historyオブジェクトにアクセスするための簡単なメソッドを提供します。
window.historyオブジェクトには、ユーザーがアクセスしたURL(Webサイト)が含まれています。
Web History APIは、すべてのブラウザーでサポートされています。
Yes | Yes | Yes | Yes | Yes |
履歴back()メソッド
back()メソッドは、windows.historyリストの前のURLをロードします。
ブラウザの「戻る矢印」をクリックするのと同じです。
例
<button onclick="myFunction()">Go Back</button>
<script>
function myFunction() {
window.history.back();
}
</script>
履歴go()メソッド
go()メソッドは、履歴リストから特定のURLをロードします。
例
<button onclick="myFunction()">Go Back 2 Pages</button>
<script>
function myFunction() {
window.history.go(-2);
}
</script>
履歴オブジェクトのプロパティ
Property | Description |
---|---|
length | Returns the number of URLs in the history list |
履歴オブジェクトメソッド
Method | Description |
---|---|
back() | Loads the previous URL in the history list |
forward() | Loads the next URL in the history list |
go() | Loads a specific URL from the history list |