JavaScript window.history.back()メソッドの使い方

環境
Windows 10 home 64bit
Google Chrome 107.0.5304.122

書式
1.window.history.back();
window.history.back()は、ブラウザの履歴リストの中の前のURLを表示します。
2.window.history.forward();
window.history.back()は、ブラウザの履歴リストの中の次のURLを表示します。

使用例

<!DOCTYPE html>
<html>
<body>
<style type="text/css">
.cft {
    font-size: 18px;
}
</style>

<div id="sample">
    <button class="cft" onclick="window.history.back();">戻る</button>
    <button class="cft" onclick="window.history.forward();">進む</button>
</div>

</body>
</html>

実行結果
「戻る」ボタンをクリックすると、ブラウザの履歴リストの中の前のURLを表示します。
ブラウザの「戻る」ボタンと同じです。
「進む」ボタンをクリックすると、ブラウザの履歴リストの中の次のURLを表示します。
ブラウザの「進む」ボタンと同じです。

JavaScript

Posted by arkgame