4

I am trying to redirect to a different page in IE9 (9.0.3).

When I try to get/set document.location, or document.location.href, or window.location/window.location.href, I'm unable to do so. It fails without giving any errors.

I've tried to check whether the document and windows objects are set, and they are, so I have no idea why the location object is "missing".

I tried getting the document.URL and that works fine, but it's read-only.

Anyone know what the problem is or how to achieve this in a cross-browser way?

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
dgivoni
  • 535
  • 2
  • 7
  • 17

5 Answers5

8

I was also experiencing the same problem but found that adding

window.event.returnValue = false;

above line in the javascript before the redirection resolved the problem.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
denmark dinga
  • 89
  • 1
  • 2
1

See this: http://social.msdn.microsoft.com/Forums/en/iewebdevelopment/thread/c864ae63-66f6-4656-bcae-86b0018d70c9

Apparently it's a caching bug, you can solve it by appending a timestamp to the destination URL (that is, using a "unique" URL every time).

Viruzzo
  • 3,025
  • 13
  • 13
  • Note that the guy in this post is doing something weird. He submits a form to (somepage) then he redirects to (somepage) - the same page. Why he didn't just submit the form without ajax idk. I think the "caching issue" is specific to this behavior. – James Nov 23 '11 at 17:21
1

Perhaps your IE9 has some security restrictions in place that prevent JavaScript from directing URL's. window.location.href = "" should work normally on IE9.

Joshua
  • 3,615
  • 1
  • 26
  • 32
0

Cache may be the reason, try:

location.href='something.php?tmp=' + Date.parse(new Date())

Hope it helps

Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
0

You should use an absolute URL:

var url = '/section/page/';
var host = window.location.hostname;
window.location = 'http://' + host + url;

Where url is the relative path to your page.

Gregory Bolkenstijn
  • 10,003
  • 7
  • 36
  • 38