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

场景如下:
[b]www.a.com下有一个页面a.html(http://www.a.com/a.html),页面的代码如下:[/b]

<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>


[b]www.b.com下有一个页面a.html(http://www.b.com/b.html),页面的代码如下:[/b]

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

<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>

不知道各位仁人志士,有没有不更改原来逻辑的情况下,解决这个问题。
谢谢
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值