onpopstate=script - history遷移時のハンドラ
属性
<タグ名 onpopstate=script>説明
同一ページ内でhisotryを遷移した際に発行されます。
サンプル
test.html
<!DOCTYPE html> <head> <title>WebMessage TEST</title> <script> window.addEventListener('load', function() { history.pushState({'page':1}, "page1", "?page=1"); history.pushState({'page':2}, "page2", "?page=2"); history.pushState({'page':3}, "page3", "?page=3"); history.pushState({'page':4}, "page4", "?page=4"); history.pushState({'page':5}, "page5", "?page=5"); window.onpopstate = function(e) { alert(JSON.stringify(e.state)); } }); </script> </head> <body> <input type="button" onclick="history.back()" value="Back"> </body> </html>
Copyright (C) 2015-2017 杜甫々
初版:2015年1月2日 最終更新:2017年12月31日
https://www.tohoho-web.com/html/attr/onpopstate.htm