`
wangyi529
  • 浏览: 34119 次
  • 性别: Icon_minigender_1
  • 来自: 大连
社区版块
存档分类

window.opener.location.href 跨域访问 在IE6,IE7,IE8不兼容

阅读更多
场景如下:
www.a.com下有一个页面a.html(http://www.a.com/a.html),页面的代码如下:
<html>
<head>
<title>a.html</title>
</head>
<body>
<a href="http://www.b.com/b.html" target="_blank">b.html _blank</a><br>
<a href="#" onclick="window.open ('http://www.b.com/b.html/')">b.html window.open</a>
</body>
</html>


www.b.com下有一个页面a.html(http://www.b.com/b.html),页面的代码如下:
<html>
<head>
<title>b.html</title>
<script>
if(window.opener!=null){
var wuri = window.opener.location.href ;
var q=getQuery(wuri);//获取父窗体地址栏的某一个参数
window.close();
window.opener.location = "http://www.b.com/login.html"
}else{
window.location = "http://www.b.com/login.html"
}
</script>
</head>
<body>
this is the b.html
</body>
</html>


以上的代码,当显示b.html时,在IE7,IE8下都没有问题,而在IE6下有js错误。
各种测试之后,发现跨域是,IE6不允许读取 window.opener.location.href 的值。
为了让以上代码不出现js错误,暂时把b.html更改为如下:

<html>
<head>
<title>b.html</title>
<script>
try{
	window.opener.location.href;
}catch(e){
	window.opener=null;
}
if(window.opener!=null){
var wuri = window.opener.location.href ;
var q=getQuery(wuri);//获取父窗体地址栏的某一个参数
window.close();
window.opener.location = "http://www.b.com/login.html"
}else{
window.location = "http://www.b.com/login.html"
}
</script>
</head>
<body>

this is the b.html
</body>
</html>

不知道各位仁人志士,有没有不更改原来逻辑的情况下,解决这个问题。
谢谢
1
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics