弹出的模态窗口如何访问父窗口的变量

场景描述:父页面有个列表,选中一行就弹出一个模态窗口,根据不同的操作,父页面将刚点过的行的按钮变灰。

父页面:

<head runat="server">

<script language="javascript" type="text/javascript">

    var clearData;
        var tmpControllerId; //用于存储当前点击的行号            
        // 弹出明细窗口
        function ShowDetail(url, id) {
            var title = "工时审批";
            var reValue = ShowWindow(url, 1000, 700, 0, title);  //弹出模态窗口
            // 去掉变灰功能
            tmpControllerId = id;
        }

</script>

</head>
<body>

<form>

....

<asp:HiddenField runat="server" ID="hidCheckBoxId" Value="" /> //隐藏域用于保存之前选中的行

<script language="javascript" type="text/javascript">                 
        var idS = document.getElementById("hidCheckBoxId").value;
        // clearData 没定义或为false表示审批未通过,就不用变灰
        if (clearData == undefined || !clearData) {
            idS = idS.replace(tmpControllerId, "");
            idS = idS.substr(0, idS.length - 1);
        }
       
        if (idS != undefined && idS != "") {
            var arrId = idS.split(';');
            for(var i = 0; i < arrId.length; i++) {
                if (arrId[i] == "") {
                    continue;
                }
               
                var objBox = document.getElementById(arrId[i]);
                objBox.disabled = "disabled";

                var objBtnId = arrId[i].replace("chkSelect", "lbtnApprove")
                var objBtn = document.getElementById(objBtnId);
                objBtn.disabled = "disabled";
                objBtn.onclick = function() { return false; }
            }
        }       
        document.getElementById("hidCheckBoxId").value = idS; 
    </script>  

    </form>
</body>

 

子页面:

<head runat="server">
    <script language="javascript" type="text/javascript">
        function ControlParentController(result) {
            window.dialogArguments[2].clearData = result;
            }

    </script>

</head>

...

子页面根据用户不同的操作,就给父页面的clearData 赋值,父页面在根据clearData 的值决定是否需要将刚选的行的按钮变灰。

 

弹出模态窗口的方法:

// 参数分别为:文件URL, 宽度, 高度, 是否有滚动条(还可以改变大写)
// 此函数解决了模式对话框中打开的窗口提交时弹出新页面的问题,使用到了ModelDialogFrame.htm文件
function ShowWindow(szUrl,iWidth,iHeight,bScroll, szTitle){
 if (iWidth == null) iWidth = 0.95;
 if (iHeight == null) iHeight = 0.7;
 
 var width,height;
 
 if (iWidth>1)
 {
  width = iWidth;
  height = iHeight;  
 }
 else
 {
  width = screen.availWidth * iWidth;
  height = screen.availHeight * iHeight;
 }
 var feature = "dialogHeight: " + height + "px; dialogWidth: " + width + "px; dialogTop: px; dialogLeft: px; edge: Sunken; center: Yes; help: No; scroll:auto;";
 if (bScroll == 1 )
 {
     feature += "resizable: Yes;  status: Yes;";
 }
 else
 {  
     feature += "resizable: No;  status: No;";
 }
 var r = Math.random() + Math.random();
 var frameUrl = "/WorkCost/js/ModalDialogFrame.htm?r=" + r;
 var args = new Array(szUrl, szTitle, window);

 return window.showModalDialog(frameUrl, args, feature);
}

 

ModelDialogFrame.htm 源码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
    <head>
      
        <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
        <meta name="ProgId" content="VisualStudio.HTML">
        <meta name="Originator" content="Microsoft Visual Studio .NET 7.1">
       
    </head>
    <body>
    <iframe id="myframe" src="" width="100%" height="100%" FRAMEBORDER="0"></iframe>
    </body>
    <script language=javascript>
<!--
if ( window.dialogArguments[0] != undefined )
{
    document.getElementById('myframe').src=window.dialogArguments[0];
 document.title= window.dialogArguments[1];
}
else
{
 document.getElementById('myframe').src=window.dialogArguments;
}
//-->
</script>
</html>

posted on 2010-02-06 14:10  一直在努力 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/itaoda/archive/2010/02/06/1664936.html

已标记关键词 清除标记
表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符 “速评一下”
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页