zoukankan      html  css  js  c++  java
  • JS模态窗口返回值兼容问题解决方案

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

    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就可以了,如下:

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

    -----------------------------------------------------------------------------------------------------------------------

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

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

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

             result = window.ReturnValue;

         }

         return result;

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

     if (typeof (window.opener) == 'undefined') window.opener = window.dialogArguments;

     

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

     window.retureValue = vals;

            if (window.opener && window.opener != null)

                    window.opener.ReturnValue = vals;

     

            window.close();


    博客园davidyang78原创,转载请保留此信息

     

    原理探讨:

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

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

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

  • 相关阅读:
    HTTP method GET is not supported by this URL
    idea 报错javax/xml/bind/DatatypeConverter
    PartyBid 学习笔记 之 第二张卡片总结
    PartyBid 学习笔记 之 第一张卡片总结
    Yeoman 之 Jade自动化生成的Grunt实现
    Jade —— 简洁的HTML模版引擎
    Underscore.JS 之 消灭for循环
    SqlServer 根据时间统计数据展示图表
    C# 中使用 JavaScriptSerializer 序列化时的时间类型处理
    jQuery 插件 autocomplete 的使用
  • 原文地址:https://www.cnblogs.com/coolsundy/p/4202390.html
Copyright © 2011-2022 走看看