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!
Archives
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- August 2005
Categories
- css (2)
- html (8)
- Interaction Design (6)
- javascript (11)
- miscellaneous (25)
- new features / improvements (55)
- panoramio (39)
- personal (2)
- places (25)
- Uncategorized (5)
The obvious come-back question is: if not location.hash = “#foo”, then what should one use to set the location hash to alter page URL without forcing a page reload?
I forgot to put in the correct way to do it:
location.hash = “foo”
the point is that explorer / firefox throw away the first # if it exists, Safari encodes it and makes it part of the hash.
Oh, now I feel a bit silly, having known (and always done) that all along.
Well, thanks for mentioning it, anyway; it’s also good to know why such code should always be fixed when encountered.
Very thans… Now it work