我有一个父网页表单,在点击按钮时打开了一个子窗口
我需要做的是在子窗口仍然打开时直接关闭父窗体,子窗口也应该关闭。
我为它编写了以下javascript
var opengridacc;
function OpenGridAccounts(companyId, checkRequestType, documentId) {
var hdnDocumentId = $(document).find('#hdnDocumentId').val();
documentId = hdnDocumentId;
opengridacc = window.open("../CheckRequest/GridAccounts.aspx?comp_id=" + companyId
+ "&CheckRequestType=" + checkRequestType
+ "&DocumentId=" + documentId,
"GridAccounts", "height=755px,width=1280px,center=yes,status=no,scrollbars=yes,toolbar=no,menubar=no,left=0,top=0");
return false;
}
function closegrdacc() {
if(!opengridacc) {
opengridacc.close();
}
}
但即出现错误,即关闭未定义
答案 0 :(得分:0)
更改closegrdacc,如下所示
function closegrdacc() {
if(opengridacc!=null)
{ opengridacc.close();
}
}
答案 1 :(得分:0)
你能试试吗,
if(opengridacc!=undefined) { opengridacc.close(); }
答案 2 :(得分:0)
您应该检查评估是否为true
。
function closegrdacc() {
// this would return false if either opengridacc is null or undefined
if(opengridacc) {
opengridacc.close();
opengridacc = null; // clean up for a new call
}
}
此外,您可能还想在打开时检查它是否已存在
var opengridacc;
function OpenGridAccounts(companyId, checkRequestType, documentId) {
if (opengridacc) // it has already been assigned a window
return false;
var hdnDocumentId = $(document).find('#hdnDocumentId').val();
documentId = hdnDocumentId;
opengridacc = window.open("../CheckRequest/GridAccounts.aspx?comp_id=" + companyId +
"&CheckRequestType=" + checkRequestType +
"&DocumentId=" + documentId,
"GridAccounts",
"height=755px,width=1280px,center=yes,status=no,scrollbars=yes,toolbar=no,menubar=no,left=0,top=0"
);
return false;
}