Javascript 删除哈希时是否触发hashchange事件?
我使用了jquery hashchange和window.addEventListener(“hashchange”),但当代码删除散列部分时,事件不会触发。我正在使用mithril.js更改哈希:Javascript 删除哈希时是否触发hashchange事件?,javascript,events,hashchange,mithril.js,Javascript,Events,Hashchange,Mithril.js,我使用了jquery hashchange和window.addEventListener(“hashchange”),但当代码删除散列部分时,事件不会触发。我正在使用mithril.js更改哈希: m.route('') window.addEventListener("hashchange", function(evt) { console.log("hash change"); var path = location.hash.substring(1); cons
m.route('')
window.addEventListener("hashchange", function(evt) {
console.log("hash change");
var path = location.hash.substring(1);
console.log(path);
//do other things
}, false);
删除url的哈希部分时是否触发事件?如果没有,处理这种情况的解决方法是什么?如果使用
history.pushState()
删除哈希,则不会触发
根据:
此外,请注意,大多数m.route
模式依赖于history.pushState
,以允许在不刷新浏览器的情况下从一页移动到另一页
如果使用
history.pushState()
删除散列,则不会触发该命令
根据:
此外,请注意,大多数m.route
模式依赖于history.pushState
,以允许在不刷新浏览器的情况下从一页移动到另一页