JavaScript/jQuery - onhashchange event workaround

痞子三分冷 提交于 2019-11-30 04:19:53

问题


Until all browsers support the onhashchange event what is the best workaround for this?

Is there something for this in jQuery? or as a plug-in?


回答1:


Not sure if this is what you're looking for or not but worth a try:

http://plugins.jquery.com/project/ba-jquery-hashchange-plugin




回答2:


Yes there is.

Check out this jQuery plugin: http://benalman.com/projects/jquery-hashchange-plugin/




回答3:


var lastHash = "";

window.onload=function()
{   
 hashChangeEventListener = setInterval("hashChangeEventHandler()", 50);
}

function hashChangeEventHandler()
{
    var newHash = location.hash.split('#')[1];

    if(newHash != lastHash)
    {
        lastHash = newHash;
        //Do stuff!
    }
}

Works fine for me across all tested (damn near all) platforms.




回答4:


http://benalman.com/projects/jquery-bbq-plugin/




回答5:


Another library that abstracts url management is History.js




回答6:


If you're looking for an iframe cross domain solution this seems to be the most robust out there:
http://easyxdm.net/wp/
http://www.cakemail.com/the-iframe-cross-domain-policy-problem/

I haven't tried it though and it seems like it could be a bit difficult to implement and might not work in all situations.



来源:https://stackoverflow.com/questions/2783760/javascript-jquery-onhashchange-event-workaround

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