其他分享
首页 > 其他分享> > 解决在Chrome下无法获取showModalDialog返回值的问题

解决在Chrome下无法获取showModalDialog返回值的问题

作者:互联网

原文链接:http://www.cnblogs.com/ricksun/archive/2012/11/13/2768374.html

今天发送的bug,正常情况下用IE和FF测试showModalDialog方法,在子页面将处理的结果赋值给window.returnValue,关闭子页面,在父页面可以通过var result=window.showModalDialog(…)获取到结果。

但chrome下result是undefine。

 

解决的办法就是,在设置返回结果时,也为window.opener.returnValue赋值。

 1: //父页面调用showModalDialog
 2: var result = window.showModelDialog(....);
 3:  
 4: //for chrome
 5: if(!result)
 6: {
 7:  result=window.returnValue;
 8: }
 9:  
 10: if(result)
 11: {
 12:  //IE/FF/CHROME都可以正常使用result
 13: }
 14:  
 15:  
 16:  
 17: //子页面
 18: var resultObj = {Pass:true};
 19: if(window.opener)
 20: {
 21:  window.opener.returnValue=resultObj;
 22: }
 23: window.returnValue=resultObj;

转载于:https://www.cnblogs.com/ricksun/archive/2012/11/13/2768374.html

标签:showModalDialog,resultObj,Chrome,window,result,returnValue,返回值,页面
来源: https://blog.csdn.net/weixin_30389003/article/details/98054953