javascript,改变location.hash时清除history

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/m940034240/article/details/84581526

通过使用以下方法来给hash赋值时

window.location.hash = 'hash的值' 

会在window.history新增一条历史记录,如果想清除掉这条记录(不清除的话点击返回会回到上一个hash值的页面),可以使用

window.location.replace(window.location.href.toString().replace(window.location.hash, '')+"#"+"hash的值")

猜你喜欢

转载自blog.csdn.net/m940034240/article/details/84581526