7

I am using Jquery Ajax for login form.After ajax success,I redirect the page using window.location.href="test.php"

This is working fine in Chrome,firefox and also in IE9.But in IE 11,it is not working.

I have tried,

window.location.replace("test.php");
window.location.assign("test.php");
setTimeout('window.navigate("test.php");', 1);
window.open('test.php','_self', null , false);

But all fails.Can anyone help?

rekha s
  • 577
  • 5
  • 7
  • 24

4 Answers4

7

Try adding a leading slash:

window.location.assign('/test.php');

Explanation
Whenever setting the location, it works very similar to clicking a hyperlink on the same page. So let's say you're at a location like this:

http://yourdomain.com/this/is/a/very/long/path.php

... and then you try to navigate away from this page with any of the following mechanisms without a leading slash:

<a href="test.php">Test Page</a>
window.location = "test.php";
window.location.href = "test.php";
window.location.assign("test.php");
window.location.replace("test.php");
window.history.pushState("Test Page", {}, "test.php");

... you will notice the URL become this:

http://yourdomain.com/this/is/a/very/long/path.php

But if you put a leading slash, /test.php, then the location becomes this:

http://yourdomain.com/test.php

Ryan Wheale
  • 26,022
  • 8
  • 76
  • 96
Med.Amine.Touil
  • 1,225
  • 2
  • 11
  • 15
  • @rekhas So the actual problem was about the leading `/` that was missing? Because in your question you mention that you tried `window.location.assign("test.php");` – t.niese Mar 05 '15 at 09:23
4

Regarding session storage, you have to make settings as follows,

Go to Tools->Internet Options and click Privacy Tab and select Advanced and in that window,check the box Override Automatic Cookie handling and Always allow Session cookies check box.

It will work.It works for me fine.

Regards,
Rekha

rekha s
  • 577
  • 5
  • 7
  • 24
1

You can use document.location instead, it works in IE11 as per this answer.

document.location.href = "test.php";
Community
  • 1
  • 1
Jai
  • 74,255
  • 12
  • 74
  • 103
  • I'm not sure if this is really correct. I also came across this answer once, but I never was able to confirm that. There where more sites and also answers here that say the opposite e.g. [window.location vs. document.location](https://stackoverflow.com/questions/7857878) (and its duplicate). Maybe the problem there was that `window.location` was used in a string passed to `setTimeout`. – t.niese Mar 05 '15 at 09:02
  • @t.niese i am also not sure but i found this answer on SO, so i suggested it. – Jai Mar 05 '15 at 09:04
0

I resolved this problem like this:

window.location.replace("test.php");

I would recommend location.assign("url") or location.replace("url") instead of location.href = url.

Calin Vlasin
  • 1,331
  • 1
  • 15
  • 21