4

Does onHashChange or hashChange work in Safari? I tested it with Safari 4.0.4 on Windows 7 and it doesn't work for me.

If it doesn't work, is there any solution to track if the hash has changed?

Adam Halasz
  • 57,421
  • 66
  • 149
  • 213

2 Answers2

1

In our app we poll to check for changes:

$b.hashCheck = setInterval(
    function(){
        if ( window.location.hash !== $b.C.current_hash){
            $b.C.current_hash = window.location.hash;

            //call the on change action here

        }
    },$b.C.hashCheckDelay
);

$b is the global object we use for our namespace and hashCheckDelay was empirically set at 120ms.
While it looks a bit sad to do this kind of process, there isn't any performance issue on any browser we tested.

Mic
  • 24,812
  • 9
  • 57
  • 70
  • thanks for your answer, this could be a solution to track if the hash has changed in the browsers who don't support `onHashChange` however this is not a good solution because with a lots of queries requires too much performance. – Adam Halasz Oct 30 '10 at 22:02
  • I use it in our app, but a single function checks and dispatch the message to the relevant object. Without problems of performance. – Mic Oct 31 '10 at 10:41
1

In Safari 4.0.4 it's not working yet but in the latest one works fine. And I didn't find any acceptable solutions to track if the hash has changed for those browsers which don't support onHashChange.

Adam Halasz
  • 57,421
  • 66
  • 149
  • 213
  • 1
    if ("onhashchange" in window) { alert("The browser supports the hashchange event!"); } – JoJo Feb 12 '11 at 18:40