且构网

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

如何使用JavaScript检测地址栏更改?

更新时间:2022-06-20 09:01:09

HTML5引入了一个 hashchange 事件,允许您注册url哈希更改的通知,无需使用计时器进行轮询。

HTML5 introduces a hashchange event which allows you to register for notifications of url hash changes without polling for them with a timer.

它受所有主流浏览器支持(Firefox 3.6,IE8,Chrome,其他基于Webkit的浏览器),但我仍然强烈建议使用一个处理事件的库 - 即在不支持HTML5事件的浏览器中使用计时器,否则使用事件。

It it supported by all major browsers (Firefox 3.6, IE8, Chrome, other Webkit-based browsers), but I'd still highly suggest to use a library which handles the event for you - i.e. by using a timer in browsers not supporting the HTML5 event and using the event otherwise.

有关该活动的更多信息,请参阅 https://developer.mozilla.org/en/ dom / window.onhashchange http:/ /msdn.microsoft.com/en-us/library/cc288209%28VS.85%29.aspx

For further information on the event, see https://developer.mozilla.org/en/dom/window.onhashchange and http://msdn.microsoft.com/en-us/library/cc288209%28VS.85%29.aspx.