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?
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?
Share Improve this question edited May 1, 2015 at 13:49 Eric Leschinski 154k96 gold badges422 silver badges337 bronze badges asked Nov 23, 2011 at 16:19 dgivonidgivoni 5552 gold badges7 silver badges17 bronze badges 2- I believe this will answer your question: stackoverflow./questions/7857878/… – Ivan Commented Nov 23, 2011 at 16:22
- It works fine for here. Can you show some relevant code? – NullUserException Commented Nov 23, 2011 at 16:25
5 Answers
Reset to default 8I 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.
See this: http://social.msdn.microsoft./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).
Perhaps your IE9 has some security restrictions in place that prevent JavaScript from directing URL's. window.location.href = "" should work normally on IE9.
Cache may be the reason, try:
location.href='something.php?tmp=' + Date.parse(new Date())
Hope it helps
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.