前台技术--window.showModalDialog带来的浏览器兼容问题

双击域的实现:http://blog.csdn.net/gaopeng0071/article/details/21179619

继此篇博文,讲述的双击域实现,在后续发现使用window.showModalDialog模态框存在浏览器兼容性问题。

使用chrome时,会出现模态框的返回值无法返回到父页面,使用此种方式: window.returnValue

这个方法存在浏览器兼容问题。采用ie内核的浏览器支持该方式,但采用谷歌内核的浏览器(如:Chrome)不支持。

不支持表现在window.showModalDialog()方法,采用谷歌内核的浏览器并不是打开一个模式弹出框而是window.open()。这样在弹出框里设置返回值window.returnValue="返回值";在父窗体获取时var  vReturnValue = window.showModalDialog(sURL [, vArguments] [, sFeatures])发现vReturnValue为undefined。


解决方案如下:

父页面:

详见其中第4行判断与第7行判断代码。

function ondbGuanLianADId(){
	adId = window.showModalDialog('getAdForMac.action', null ,'dialogHeight=500px; dialogWidth=420px;');
	var strs = adId;
    if(strs==undefined){
    	strs=window.returnValue;
    }
	if(strs != undefined){
		document.getElementById("guanLianADId").value = strs.split(":")[0];
		document.getElementById("guanLianADName").value = strs.split(":")[1];
	}
}
子页面:

function test(){
	// 解决IE与chrome浏览器版本差异问题
	 if (window.opener != undefined) {
         //for chrome  
         window.opener.returnValue = document.getElementById("name1").value;
     }
     else {
         window.returnValue = document.getElementById("name1").value;
     }
	window.close();
}


参考资源:http://blog.csdn.net/luckzhang_la/article/details/17262421


  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值