window.location.href在IE 11中不起作用 [英] window.location.href not working in IE 11

查看:102
本文介绍了window.location.href在IE 11中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jquery Ajax登录表单。在ajax成功之后,我使用重定向页面window.location.href =test.php

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

这在Chrome,Firefox和IE9中运行良好。但在IE 11中,它无效。

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

我有试过,

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?

推荐答案

尝试添加一个前导斜杠:

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");

...您会注意到URL变为:

... you will notice the URL become this:


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

但是如果你把一个领先的斜杠, /test.php ,然后该位置变为:

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


http://yourdomain.com/test.php

这篇关于window.location.href在IE 11中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆