【发布时间】:2011-06-16 19:18:36
【问题描述】:
我的 jQuery 脚本中有一个简单的重定向。您单击一个链接,它会执行异步保存,然后通过 window.location.href 将用户发送到下一页。这在所有浏览器中都可以正常工作,除了我在 IE 中遇到问题(惊喜)。在 IE 的一页上,尝试运行脚本时出现以下错误
E.location.protocol is null or not an object
奇怪的是,该脚本可以在其他页面上运行。我唯一能看到的不同之处在于它所在的页面包含谷歌地图,而其他页面则没有。
此外,这似乎只是在更高版本的 jQuery(1.4+)中才有问题,但我必须将其用于其他功能。
有什么建议吗?谢谢。
保存、重定向脚本(从页面锚标记中的“goto”属性获取其位置):
$("#save_and_go_button").click(function(){
showAction('Saving...');
$.ajax({
type: "POST",
url: "/admin_and_tools/async/save.php",
data: $("#main_form").serialize(),
dataType: "html",
success: function(results){
if(results == 'success'){
hideAction();
//alert('The record has been saved.');
document.location.href = $("#save_and_go_button").attr('goto');
}else{
alert('failed' + results);
}
}
});
});
编辑:这是它在 jQuery 代码中所做的行:
if(E.location.protocol!=="file:")
try{return new E.XMLHttpRequest}catch(a){}try{
return new E.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}};
【问题讨论】:
-
仅供参考,您正在访问
document.location.href(无论如何都应该工作,以防万一) -
"document.location.href " 与 "window.location.href" 不完全相同 - document... 应该是只读的,但有些浏览器不支持这一点。
标签: jquery internet-explorer redirect href