<button class="btn1">追加历史</button> <button class="btn2">替换当前历史</button> <script> document.querySelector('.btn1').onclick = function () { /*1.存数据 null*/ /*2.存标题 null*/ /*3.追叫的历史记录的地址*/ history.pushState(null,null,'test.html'); } document.querySelector('.btn2').onclick = function () { /*1.存数据 null*/ /*2.存标题 null*/ /*3.替换的历史记录的地址*/ history.replaceState(null,null,'test.html'); } window.onpopstate = function(){ /*监听历史切换事件*/ /*当前地址 没有包括域名*/ console.log(location.pathname); } </script>
h5 history
最新推荐文章于 2023-10-19 17:10:26 发布