Modal screen does not close after searching the Iframe inside it

Asked

Viewed 162 times

0

I decided to open this post, because the same is continuation of a post I did, but with the following difference. The research I was having trouble doing from a Modal screen with Iframe in ASP now works. The point now is that the Modal screen does not close after the search, but the search works, because if I close Modal manually, it works. See below the code, which colleague Tobymosque helped me to do(merits of it).

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(create)

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 so: var janela = null; and I follow the code as it is, makes that mistake:

Uncaught Typeerror: Cannot read Property 'Document' of null

If I copy the window declaration in the select function and paste in the close function, it still gives this error. On hold.

  • It worked like this: var closeModal = Function () { var dialog = $(Document.getElementById("dialog1"); dialog.dialog("close"); }

  • I would like to give credit to Mr Tobymosque for his effort and commitment in trying to help me.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.