JS模态窗口返回值兼容问题的完美解决方法

因系统要兼容原IE已使用的关闭方法,经调试测得,需对window.dialogArguments进行再较验,不然易出问题。

rush:js;"> function OKEnd(vals) { if (vals == null) vals = "TRUE"; if (typeof (window.opener) == "undefined") { if (typeof (window.dialogArguments) != "undefined") { if (window.dialogArguments && window.dialogArguments != null) { window.opener = window.dialogArguments; if (window.opener && window.opener != null) { window.opener.ReturnValue = vals; } } } } else { if (window.opener && window.opener != null) { window.opener.ReturnValue = vals; } } window.returnValue = vals; self.close(); }

返回值接收的,只需在原有IE的接收模式下,多较验一下opener就可以了,如下:

rush:js;"> //选择变更部门 function SetorganizeTree2() { var url="弹出页面"; var ret = window.showModalDialog(url,window,"dialogWidth=400px;dialogHeight=500px;status=no;help=no;scroll=yes;resizable=yes;"); if (typeof (ret) == "undefined") { ret = window.ReturnValue; } if (ret) { document.getElementById("hidDeptCode2").value = ret; document.getElementById("btnDeptCodeAdd").click(); } return false; }

JS模态窗口返回值兼容问题完美解决方法

1、打开弹出窗口时把 window 作为第二个参数传入。

rush:js;"> var result = window.showModalDialog(url,"dialogWidth=" + width + "px;dialogHeight=" + height + "px;resizable:yes;")

if (typeof (result) == 'undefined') {

 result = window.ReturnValue;

}

return result;

2、在弹出窗口中,执行如下JS,以接收传入的window

rush:js;"> if (typeof (window.opener) == 'undefined') window.opener = window.dialogArguments;

3、弹出窗口关闭前,调用如下JS赋返回值

rush:js;"> window.retureValue = vals;
if (window.opener && window.opener != null)

    window.opener.ReturnValue = vals;



window.close();

原理探讨:

chrome下,标准方法,在弹出页面不回发的情况下,是可以返回值的。 有回发则不能正常返回值。此方法可以解决

IE下标准方法,有时不明原因不能正确返回值,此方法解决

FF未详细测试,应该问题不大。

以上这篇JS模态窗口返回值兼容问题的完美解决方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程之家。

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...