0

问题是(至少在我当前的浏览器中),更改哈希标记并输入新的 url 不会触发页面刷新,因此我不知道如何检测何时进行了哈希标记更改。

有没有一种优雅的方式来做到这一点?

4

2 回答 2

1

检查一个新的location.hash

于 2011-05-15T05:23:43.250 回答
0

这是一个讨厌的解决方案,但您可以不时轮询 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);
于 2011-05-15T05:25:03.437 回答