Yay for stupid IE7 anchor bug!

Posted by james on March 24, 2009

So I'm testing a site out for cross-browser compatibility. It works great in Firefox 3, so now I'm testing in Internet Explorer 7, and I'm getting a strange bug. When the site goes to url#hash, IE7 jumps to the middle of the page, while Firefox does not. This is strange because normally for the #hash to jump anywhere, there must be a target somewhere on the page. The whole point of the #hash I'm using is that it doesn't exist on the page, so there shouldn't be any scrolling/jumping around.

Now, normally if you have this:
<a href="#some_hash">link</a>
<a name="some_hash">Target</a>

This means if you click on "link", the page will jump to "Target". If you have this:
<a href="#some_hash">link</a>
Clicking on that link will update the URL but will not move the page, since #some_hash doesn't exist on the page. According to the W3C, the target can also be any element with id="some_hash". Ok, good to know.

But of course, IE7 likes to do its own things just to screw with me.
<a href="#some_hash">link</a>
<input name="some_hash"/>

In this case, when the user clicks on "link", the page will jump to the input with the name of "some_hash", in violation of the w3c standard. This is incredibly annoying... yet another example of how screwed up the IE7 team is. How in the world did this get past testing? More incredibly, how in the world did this get in there in the first place? Do they just sit around in meetings and think up new ways to make IE7 "stand out from the crowd" (ie. introduce bugs)? It sure seems so sometimes.