总结showModalDialog在开发中的一些问题

一、在页面调用window.open()函数后,可以直接在打开的页面中用window.opener来调用父页面的方法,然而如果用showModalDialog打开一个模态窗口,就不能通过window.opener去调用父窗口的方法了,这时,要用window.dialogArguments去调用,注意在showModalDialog方法中的第二个参数是window,即把当前窗口传给子页面,所以子页面才可以通过window.dialogArguments去调用父页面的方法。
父页面js如下:

   //显示设置页面
        function showSet(url) {
            //showWin(800, 600, "FieldShowSet.aspx" + url, "set");
            open_Dialog("FieldShowSet.aspx" + url, window, 800, 640);
        }
        //触发查询事件
        function searchData() {
            var btn = document.getElementById("<%=btnQuery.ClientID %>");
            btn.click();
        }

子页面js如下:

  function CloseWin() {
        //alert('设置成功!'); window.opener.searchData(); window.close();
        var pWindow = window.dialogArguments;
        if (pWindow != null) {
            pWindow.searchData();
        } else {
            window.opener.searchData();
        }
        window.close();
    }
二、当我们在模态窗体中刷新时,会打开一个新页面,这是我们可以通过在<head>中加上如下代码解决这一问题:
<base target="_self"/>
另外,当在模态窗体中刷新时,由于是提交到当前页,数据并不会更改,因为它是从页面缓存中读取数据,要让其变更,我们可以通过在<head>中添加如下代码清除缓存即可:
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="cache-control" content="no-cache,must-ridate"/>
<meta http-equiv="expires" content="0"/>
三、模态窗体居中显示
//路径地址,window对象,宽,高
function open_Dialog(url, win,Width, Height) {
    var return_Value;
    var iTop2 = (window.screen.availHeight - 20 - Height) / 2;
    var iLeft2 = (window.screen.availWidth - 10 - Width) / 2;
    var height2 = Height - 40;
    if (document.all && window.print) {
        return_Value = window.showModalDialog(url, win, "dialogLeft:" + iLeft2 + "px;dialogTop:" + iTop2 + "px;dialogWidth:" + Width + 
"px;dialogHeight:" + Height + "px;center:yes;status:no;scroll:no;help:no;");
    }
    else {
        window.open(url, win, "top=" + iTop2 + ",left=" + iLeft2 + ",width=" + Width + "px,height=" + height2 + "px,resizable=1,scrollbars=0");
    }
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

邹琼俊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值