Monday, March 3, 2008

IE6: Location.href in onclick event not working

I stepped on this problem today, and it was driving me crazy, until I found the link below:
Problem:
If you have
1. A hyperlink with an onclick attribute that calls...
2. A JavaScript function that sets the location.href value...
3. and an href attribute with a javascript: protocol value that does nothing (void)

then, when clicking on the link, IE6 won't leave the page you are on.

Workaround:
Use the hash anchor naming option. If you use a non-existent value, then the browser won't scroll either! ;-)
<a href="#none" onclick="doThis();">This works</a>

More info and example on:
http://webbugtrack.blogspot.com/2007/09/bug-223-magical-http-get-requests-in.html

No comments: