JavaScript/jQuery - onhashchange event workaround

时间秒杀一切 提交于 2019-11-30 20:19:47

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

Yes there is.

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

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.

Another library that abstracts url management is History.js

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.

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