Changing window.location in IE 6
For some crazy reason, IE 6's crazy Javascript engine doesn't want to take me to a new URL by simply changing the window.location or window.location.href properties:window.location = newUrl;
// This also doesn't work!
// window.location.href = newUrl;
But, the following code which shouldn't make a difference does work!
setTimeout(function()
{
window.location = newUrl;
}, 0);
Go figure!
Comments
Weird... I've never had a problem like that with window.location. IE never ceases to amaze, eh? What's the context? When does this get called? - Luke, Thursday, October 23, 2008 On a link whose href is just a empty Javascript function, and who has an "onclick" observer (Element.observe("click", ....)). - Patrick, Thursday, October 23, 2008 Thanks for posting this man. I had the same problem, and this bizarre solution worked for me. Sure enough, ie6 continues to amaze. - Tyler, Tuesday, February 3, 2009 thanks for the solution, i was pulling my hair out. - ricky, Thursday, February 12, 2009 thx a lot ... it works great for me - 2rock, Wednesday, March 11, 2009 Thanks a lot - nature, Sunday, March 22, 2009 You'd have to ask the developers at Microsoft as to why this is the case. IE6 is full of many wonderful surprises that require equally wonderful work-arounds. - Patrick, Monday, March 23, 2009 Thanks a lot it saved me time - Sarathc, Wednesday, April 8, 2009 Thanks for the tip! - A_Flama, Tuesday, April 28, 2009 Thanks pal, this really helped me out - Graham, Thursday, May 28, 2009 And what about document.location? - Dmitry, Monday, July 6, 2009 Thanks for the solution!!! - nexus, Thursday, July 9, 2009 I've been trying to figure that out for ages! Thanks a lot! I really should spend a little more time working on JS rather than all Perl! - Graeme Lawton, Monday, July 13, 2009 cool, I havn't ran into this problem - yet! But im sure I will! Thanks! Also, "You'd have to ask the developers at Microsoft as to why this is the case. IE6 is full of many wonderful surprises that require equally wonderful work-arounds." I wouldnt call any of IE6's problems wonderful, more like mind numbingly stupid problems that shouldn't even exist in the first place! - tan social news pirate, Monday, July 13, 2009 thanks :) this solved a very annoying problem for me! - Rob, Thursday, July 23, 2009 had this issue. weird but it worked. thanks.. - yasar, Wednesday, September 16, 2009 Worked! Thanks! - Sona, Tuesday, October 13, 2009 Thank you! That was surely a frustrating experience until I came across your post! - Sean, Thursday, November 5, 2009 I think IE6 might do some action wrapping when passing a function argument. Whereas, directly setting may not raise event to make it effect. I did have simliar experience when debugging my GUI coding using Javascript in IE6. - scottchu.tw, Monday, December 14, 2009 Thanks for the post! It helped me. :) - Lalit Mehta, Wednesday, January 13, 2010 It works! thank you very much. - munk, Monday, March 1, 2010 |
Post a comment |
