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

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

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

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

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

  • 摘自:http://blog.csdn.net/luckzhang_la/article/details/17262421

这个方法存在浏览器兼容问题。采用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