IE浏览器不兼容的与window.location.href [英] IE incompatability with window.location.href

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

问题描述

我使用了一个回调从一个AJAX POST请求导航到一个新的页面,但它不工作的IE浏览器。我的code是如下:

I'm using a callback from an AJAX post request to navigate to a new page, but it is not working on Internet Explorer. My code is as follows:

$.ajax({ 
    type: "POST",
    url: phpUrl,  
    data: data,  
    async: false, 
    success: function() {       
         if (navigator.appName == 'Microsoft Internet Explorer'){   window.location.href("/step2.php")}
         else{ window.location.href = "/step2.php"}             
    },  
    dataType:'json'         

}); 

这工作正常FF / Safari /铬,但是当我测试它在IE浏览器无法正常工作。有没有重定向到一个新的页面更好的办法?我使用异步:假我的数据没有被加载在Chrome / Safari浏览器,如果我不使用回调的页面会在 POST 要求是完整的。

This works fine on FF/Safari/Chrome but when I test it on IE it does not work. Is there a better way of redirecting to a new page? I'm using async:false as my data was not loading on Chrome/Safari if I did not use a callback as the page would just change before the POST request was complete.

推荐答案

这是括号。 的href 不是一个函数,因此试图调用它— window.location.href(/ step2.php)—是类型错误

It's the parentheses. href is not a function, so trying to invoke it—window.location.href("/step2.php")—is a TypeError.

分配给的href 像你这样的下一行,或更好的,使用的 location.assign()

Assign to href like you do on the next line, or better, use location.assign():

location.assign('/step2.php');

虽然您可以直接分配给位置的属性( location.href ='...'; ),以使浏览器导航,我不推荐这个。

While you can directly assign to location's properties (location.href='...';) to cause the browser to navigate, I recommend against this.

在内部,这样做仅仅是调用 location.assign()无论如何,分配给属性的并不总是表现在所有浏览器相同的的。

Internally, doing so is just calling location.assign() anyway, and assigning to properties does not always behave the same in all browsers.

关于异步:假 永远的做到这一点。如果你犯了一个同步XHR请求, 你就错了 <一个href="http://blogs.msdn.com/b/ieinternals/archive/2011/08/03/do-not-use-xmlhtt$p$pquest-in-synchronous-mode-unless-you-like-to-hang.aspx"相对=nofollow> 8.4%报IE9挂起的是由于同步XHR阻止浏览器。

Regarding, async:false, never do that. If you make a synchronous XHR request, you're doing it wrong. 8.4% of reported IE9 hangs were due to synchronous XHR blocking the browser.

既然你拥有了它在回调中,分配给位置将不会发生,直到P​​OST完成,所以我不知道你所说的平均在POST完成之前,页面会改变。 (你忘了取消表单的提交?)

Given that you have it in a callback, the assignment to location won't happen until the POST completes, so I'm not sure what you mean by "the page would change before the POST completes." (Did you forget to cancel a form's submit?)

这篇关于IE浏览器不兼容的与window.location.href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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