Jquery + up to date hash change listener?

筅森魡賤 提交于 2019-12-11 15:35:46

问题


I'm using http://benalman.com/projects/jquery-hashchange-plugin/ to listen for hash changes in my project, but his plugin is outdated and does not work with newer versions of browsers such as Firefox 9 and IE9.

Searched on Google and here but could not find any other plugin.

Or is it enough to just use this code to target most of the browsers?

$(window).bind('hashchange', function() {
    //code
});

EDIT: Seems like there was a problem regarding console.log() on these browsers and had nothing to do with the hashchange. It works like expected after removing all console.log output


回答1:


Plugin you are using is still the best one available. For IE9 support check out this. Also consider some alternative for browsers that do not support hash change event (this may help).




回答2:


If any url change would work, you might look at history.js But you should probably test for native support and use the native event where it exists, and use the plugin to fix older browsers that don't support the native event, which is what the plugin you referenced is designed to do.



来源:https://stackoverflow.com/questions/8908172/jquery-up-to-date-hash-change-listener

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