Saturday, January 7, 2006

Little incompatibilities between browsers

On the series of incompatibilites between browsers, I have two new items to show.

First, don't use location.hash = "#foo" to jump to "foo" link, because Safari will jump to %23foo. Safari's behaviour seems very logic, but I don't really know who is right, Safari or the IE / Firefox crowd.

Second, don't use
<a h ref="javascript:void(foo())" >foo</a>

You should really do
<a h ref="something.html" onclick="foo(); return false">foo</a>

For the purist out there, yeah, that's not exactly equivalent, onclick="try { foo() } finally { return false } gets you closer, but the value of this will still be different in the two foo's.
Putting javascript:void(foo()) in the href turns out to produce buggy results, because once a user clicks in a link, and Internet Explorer engine passes onclick's or any other guard and reaches href, then it enters in a different state, that only quits when the new page loads (a href to an anchor is of course an exception).

In this new state, animated gif images stop their animation and Bad Things Happen™. Among others, expect your javascript code to fail in subtle ways. Explorer is not expecting to execute javascript code after you click on a link. It's already hard enough to make it behave correctly on its natural state, so trying to do something useful after a successful click on a link is roulette.

P.S.: WordPress 2.0 is nice and all, but it's html editor is a pain. I had to put the above html code in a pre tag, using entities, and breaking h ref (like here) because otherwise it changes it!