June 6, 2007

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!

Filed under: Javascript — Michi @ 10:28 pm

Share this

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Reddit
  • StumbleUpon
  • del.icio.us
  • description
  • Technorati
  • Slashdot
  • co.mments
  • NewsVine

Related

Yesterday, I hit a wall in PHP that took a little brain power to solve. I posted the solution on the web for everybody to see. A little back-story: Constants in PHP (the const keyword) can not have dynamic values....
Someone asked me to write this a long time ago, so here's my list. I make the basic assumption that you at least know some SQL. 1. Use EzSQL. It is an open source library that does database abstraction....

3 Comments »

TrackBack URI | Blog RSS | Comment RSS

  1. Thanks. This just solved a bug I’ve been trying to fix for 3 days.

    Comment by Bryce — December 14, 2007 @ 11:59 am

  2. 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

  3. 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

What do you think?