且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检测JavaScript中的URL更改

更新时间:2022-02-20 22:00:55

在现代浏览器(IE8 +,FF3.6 +,Chrome)中,你可以只听窗口上的 hashchange 事件。

In modern browsers(IE8+, FF3.6+, Chrome), you can just listen to the hashchange event on window.

在一些旧的浏览器,你需要一个持续检查 location.hash 的计时器。如果您正在使用jQuery,那么插件就是这样做的。

In some old browsers, you need a timer that continually checks location.hash. If you're using jQuery, there is a plugin that does exactly that.