jQuery window.location.href 在 IE 11 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28872598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
window.location.href not working in IE 11
提问by rekha s
I am using Jquery Ajax for login form.After ajax success,I redirect the page using window.location.href="test.php"
我正在使用 Jquery Ajax 作为登录表单。ajax 成功后,我使用重定向页面 window.location.href="test.php"
This is working fine in Chrome,firefox and also in IE9.But in IE 11,it is not working.
这在 Chrome、firefox 和 IE9 中工作正常。但在 IE 11 中,它不起作用。
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?
但一切都失败了。有人可以帮忙吗?
回答by Med.Amine.Touil
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:
说明
每当设置位置时,它的工作方式与单击同一页面上的超链接非常相似。假设您在这样的位置:
... 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:
...你会注意到 URL 变成了这样:
But if you put a leading slash, /test.php, then the location becomes this:
但是如果你放一个前导斜杠/test.php,那么位置就会变成这样:
回答by rekha s
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.
转到“工具”->“Internet 选项”,然后单击“隐私”选项卡并选择“高级”,然后在该窗口中选中“覆盖自动 Cookie 处理”和“始终允许会话 cookie”复选框。
It will work.It works for me fine.
它会工作。它对我很好。
Regards,
Rekha
问候,
雷卡
回答by adSad
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
.
我会推荐location.assign("url")
或location.replace("url")
代替location.href = url
.
回答by Jai
You can use document.location
instead, it works in IE11 as per this answer.
您可以document.location
改用,它可以根据此答案在 IE11 中工作。
document.location.href = "test.php";