JavaScript/jQuery - onhashchange event workaround

后端 未结 6 1249
再見小時候
再見小時候 2021-01-05 08:26

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?

相关标签:
6条回答
  • 2021-01-05 08:48

    Yes there is.

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

    0 讨论(0)
  • 2021-01-05 08:48

    Another library that abstracts url management is History.js

    0 讨论(0)
  • 2021-01-05 08:55

    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.

    0 讨论(0)
  • 2021-01-05 08:58

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

    0 讨论(0)
  • 2021-01-05 08:59

    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

    0 讨论(0)
  • 2021-01-05 09:07
    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.

    0 讨论(0)
提交回复
热议问题