![](/img/trans.png)
[英]Is there a way to fire a 'hashchange' event even if the hash is the same?
[英]Does hashchange event fire when hash is removed?
我同时使用了jquery hashchange和window.addEventListener(“ hashchange”),但是当哈希部分被代码删除时,该事件不会触发。 我正在使用mithril.js更改哈希值:
m.route('')
window.addEventListener("hashchange", function(evt) {
console.log("hash change");
var path = location.hash.substring(1);
console.log(path);
//do other things
}, false);
移除网址的哈希部分时会触发该事件吗? 如果没有,解决此情况的解决方法是什么?
如果使用history.pushState()
删除哈希,则不会触发。
根据mithril.js docs :
另外,请注意,大多数
m.route
模式都依赖于history.pushState
,以允许在不刷新浏览器的情况下从一页移动到另一页。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.