IE Redirect Bug with Dynamic Location Hash
I discovered the most obscure bug today in IE. For those of you paying attention, this bug is the reason I haven’t been updating — it ate up all my god-damned time. People who aren’t programmers can stop reading here.
What Happens
The browser is redirected when it shouldn’t be after modifying the URL hash (the stuff after #).
Scope
The bug exists on IE7, possibly 6 (why not, right?).
Steps to Reproduce
Assume you are on page A and want to redirect to page B.
- Go to page A.
- From page A, do a header redirect to page B in PHP/ASP/whatever. As in, header(’location: $pageB’);
- On page B, using JavaScript, modify the document.location.hash variable.
What Should Happen
The anchor text in the address bar should change. As in, http://www.michiknows.com/#someanchor changes to http://www.michiknows.com/#newanchor. This should happen without the page refreshing.
What Actually Happens
The browser refreshes. @#%!*(&$!
Solution / Fixes
On page A, rather than redirect using headers, use JavaScript:
<script>
// if page A was http://www.michiknows.com
document.location.href = ‘http://www.michiknows.com/’;
</script>
<a href=”http://www.michiknows.com”>go to page A</a>
For some dumb reason, this fixes the problem.
Damn you, Microsoft!









Thanks. This just solved a bug I’ve been trying to fix for 3 days.
Comment by Bryce — December 14, 2007 @ 11:59 am
i found a related bug.
in server side a.aspx :
Response.Redirect(”test.aspx?v=123#a”);
in test.aspx:
Request["url"] is “123#a”
but Request["url"] should be “123″
it only exists on IE6. IE7 and Firefox are OK.
Comment by jim — March 26, 2008 @ 6:38 am
i found a related bug.
in server side a.aspx :
Response.Redirect(”test.aspx?v=123#a”);
in test.aspx:
Request["v"] is “123#a”
but Request["v"] should be “123″
it only exists on IE6. IE7 and Firefox are OK.
Comment by jim — March 26, 2008 @ 6:38 am
Dude,thanks alot. I wasted several days trying to figure this out.
Comment by ethaniel — October 13, 2008 @ 4:32 am