![](/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.