Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.location.href not working in IE 11

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?

like image 941
rekha s Avatar asked Mar 05 '15 07:03

rekha s


People also ask

Does window location work in all browsers?

The window. location is read/write on all compliant browsers.

What is the difference between window location and location href?

window. location is an object that holds all the information about the current document location (host, href, port, protocol etc.). location. href is shorthand for window.

Does window location href return a string?

The href property of the Location interface is a stringifier that returns a string containing the whole URL, and allows the href to be updated.


2 Answers

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

like image 193
Med.Amine.Touil Avatar answered Oct 05 '22 23:10

Med.Amine.Touil


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

like image 33
rekha s Avatar answered Oct 06 '22 00:10

rekha s