MJLefevre
MJLefevre

Reputation: 815

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?

Upvotes: 7

Views: 14662

Answers (6)

Tomasz Zieliński
Tomasz Zieliński

Reputation: 16346

Another library that abstracts url management is History.js

Upvotes: 1

Mike
Mike

Reputation: 61

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.

Upvotes: 6

tkane2000
tkane2000

Reputation: 495

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.

Upvotes: 0

gurun8
gurun8

Reputation: 3556

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

Upvotes: 10

Piotr Rochala
Piotr Rochala

Reputation: 7781

Yes there is.

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

Upvotes: 8

Related Questions