Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
问题是(至少在我当前的浏览器中),更改哈希标记并输入新的 url 不会触发页面刷新,因此我不知道如何检测何时进行了哈希标记更改。
有没有一种优雅的方式来做到这一点?
检查一个新的location.hash
location.hash
这是一个讨厌的解决方案,但您可以不时轮询 URL 以进行更改:
var hash = window.location.hash; function poll() { if (window.location.hash != hash) { hash = window.location.hash; // Hash has changed. Do stuff here. } } setInterval(poll, 100);