I decided to open this post, because the same is a continuation of a post I made, but with the following difference. The search I was having difficulty making from a Modal screen with IFrame in ASP, now works. The question now is that the Modal screen does not close after the search, but the search works, because if I close the Modal manually, it works. See below the code, which colleague TobyMosque helped me to do (his merits).
function selecionar(num_contrato, cod_ts_contrato, nome_entidade){
<%if trim(strAction) = "" then %>
//ABRIU POPUP
var janela = null;
var isIFrame = false;
var isPopUp = false;
if (window.dialogArguments) {
isPopUp = true;
janela = window.dialogArguments;
} else if (window.parent.opener) {
isPopUp = true;
janela = window.parent.opener;
} else if (window.parent.frameElement) {
isIFrame = true;
var documento = window.parent.frameElement.ownerDocument
var janela = documento.defaultView || documento.parentWindow;
}
if (janela) {
var form01 = janela.document.form01 || janela;
var cod_ts_contrato_id = "<%= trim(txt_nome_campo_cod_ts) %>" || "cod_ts_contrato";
var num_contrato_id = "<%= trim(txt_nome_campo_cod) %>" || "num_contrato";
var nome_contrato_id = "<%= trim(txt_nome_campo_desc) %>" || "nome_contrato";
var funcao_executar_id = "<%= trim(funcao_executar) %>";
var indsubmit = "<%= lcase(indsubmit) %>" === "true";
var ocod_ts_contrato = form01[cod_ts_contrato_id];
var onum_contrato = form01[num_contrato_id];
var onome_entidade = form01[nome_contrato_id];
var ofuncao_executar = funcao_executar_id ? janela[funcao_executar_id] : null;
if (ocod_ts_contrato) ocod_ts_contrato.value = cod_ts_contrato;
if (onum_contrato) onum_contrato.value = cod_ts_contrato;
if (onome_entidade ) onome_entidade .value = nome_entidade;
if (typeof ofuncao_executar === 'function') ofuncao_executar();
if (indsubmit) {
form01.submit();
} else if (onum_contrato != null && onum_contrato.disabled==false && onum_contrato.enabled==true) {
onum_contrato.focus();
}
}
if (isIFrame) {
janela.fecharModal();
}
if (isPopUp) {
parent.self.close();
}
<%else %>
//ABRIU NORMAL ENTAO DAR SUBMIT
document.form01.cod_ts_contrato.value = cod_ts_contrato;
document.form01.num_contrato.value = num_contrato;
document.form01.action = '<%Response.write strAction & "?PT=" & Request("PT")%>';
document.form01.submit();
<%end if %>
}
Here is the code on the parent screen (modal caller). Code to close Modal
var fecharModal = function () {
var dialog = $(janela.document.getElementById("dialog"));
dialog.dialog("close");
}
Code to open Modal
var dialog = $("#dialog1");
var openModal = $("#btnLupa");
var frame = window.frameElement;
dialog.dialog({
modal: true,
autoOpen: false,
});
dialog.load(function () {
dialog.dialog("open");
});
var AbrirModal = function (url, title, width, height) {
dialog.attr("src", url);
dialog.dialog("option", "title", title);
dialog.dialog("option", "width", width);
dialog.dialog("option", "height", height);
}
With all these codes this is the error that gives: Does not recognize window. If I declare: var janela = null;
and I follow the code as it is, it gives this error:
Uncaught TypeError: Can not read property 'document' of null
If you copy the window statement in the select function and paste it in the close function, you still give this error. I'm waiting.