How to detect change of window hash?

耗尽温柔 提交于 2019-12-01 20:05:27

Ben Alman's hashchange jQuery plugin provides the ability to monitor the hash for changes.

nrabinowitz

Most recent browsers (FF3.6+, IE8, Chrome) support the "hashchange" event on the window object - see MDC: window.onhashchange for usage examples. Simple asynchronous listening might look like:

window.onhashchange = function() {
   // do something awesome here
};

If you want an implementation that supports older browsers, things get complicated quite quickly, and I recommend using someone else's library or plugin - see answers to this question for several suggestions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!