Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript/jQuery - onhashchange event workaround

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?

like image 376
MJLefevre Avatar asked May 06 '10 19:05

MJLefevre


4 Answers

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

like image 94
gurun8 Avatar answered Oct 09 '22 19:10

gurun8


Yes there is.

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

like image 36
rochal Avatar answered Oct 09 '22 17:10

rochal


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.

like image 20
Mike Avatar answered Oct 09 '22 18:10

Mike


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

like image 33
user422528 Avatar answered Oct 09 '22 18:10

user422528