Showmodaldialog polyfill:如何通过调用函数将值传递给父窗口和关闭的对话框

本文关键字:窗口 对话框 值传 polyfill 何通过 调用 函数 Showmodaldialog | 更新日期: 2023-09-27 18:06:45

有问题在Google Chrome, showmodaldialog不工作,所以我使用showmodaldialog.js从polyfill。

我有两个aspx页面,一个用于父窗口页面parentpage.aspx和一个用于弹出对话框emplsearch.aspx。对话框工作,但我在传递值从对话框到父窗口的问题,对话框不能通过点击emplsearch.aspx上的点击javascript函数imbSelect imagebutton关闭。我试着这样写:

function quitBox(cmd, msg) {
    if (cmd == 'quit') {
        open(location, '_self').close(); // this works for firefox, but chrome doesnt work
        dialog.close();  // error in console in here... dialog doesnt closed in chrome
       setValuesToParent(msg); // start to pass value to parent window
    }
    return false;
}
function setValuesToParent(msg) {
    parent.window.document.getElementById('txbPinjamBy').value = msg[2];  // this doesnt work too...  error : Cannot set property 'value' of null
    window.opener.setValues(msg); // this is the important line 
};

谢谢

Showmodaldialog polyfill:如何通过调用函数将值传递给父窗口和关闭的对话框

要将模态文档(emplsearch.aspx)的值传递给父文档(parentpage.aspx),只要它们处于相同的源,只需调用:

function quitBox(cmd, msg) {
    if (cmd == 'quit') {
        window.returnValue = msg;
        parent.document.getElementsByTagName('dialog')[0].close();
    }
}

然后,在父文档中,像这样调用模态:

var retVal = window.showModalDialog('emplsearch.aspx');

问题是模型对话框不返回值。下面的代码用于对话框

window.returnValue = indexName + "$$" + selArrString;
var agentStr = navigator.userAgent;
if (agentStr.indexOf("Chrome") >- 1) {
    // Based on their suggestion I added this line 
    parent.document.getElementsByTagName('dialog')[0].close();
    // (In order to close the dialog from inside of it, invoke                         
    //     parent.document.getElementsByTagName('dialog')[0].close();
    // provided that both documents have the same origin.)
} else {
    self.close();
}