window.showmodaldialog not working in chrome

Deadly 提交于 2020-01-13 07:01:46

问题


I'm using VS2010 Express edition for my project.

I have created one registration form which is having "Submit" button, which will open up the new window (child window).

It contains aspx button ( ).

Child window again contains a form which is filled up by us and after clicking on Save button that form gets saved and after getting saved if we close the child window then the registration form gets submitted.

Page load contains a function which is calling the javascript.

SetJavaScript();
        if (Session["IsSuccess"] != null)
            if (Session["IsSuccess"].ToString().ToLower() == "success")
                TextBox1.Text = Session["IsSuccess"].ToString();
        if (ddlTicketType.SelectedValue.ToString().ToLower() == "cr")
            btnSubmit.Attributes.Add("OnClick", "OpenChild(); ");
        if (ddlTicketType.SelectedValue.ToString().ToLower() == "pr")

btnSubmit.Attributes.Add("OnClick", "clickno();");

Since window.showmodaldialog is not working on chrome. I have used window.open also but its also not working properly as it open up the child form and after closing it registration form having error message "Please fill up the form". Below is the javascript code which is getting called on page load.


private void SetJavaScript()
   {
    string str_Script = "";
    str_Script += "<script type='text/javascript' language='javascript'>";
    str_Script += "function OpenChild() ";
    str_Script += "{ CheckValidation();";
    str_Script += "var varx = document.getElementById('TextBox1').value;";

    str_Script += "if (varx== 'yes'){";
    str_Script += "var ParmA = '2';";
    str_Script += "var MyArgs = new Array(ParmA);";
    str_Script += "if (ParmA=='2'){";
    str_Script += "var WinSettings = 'center:yes;resizable:yes;dialogheight:800px;dialogwidth:1000px';";
    str_Script += "MyArgs = window.showModalDialog('user/cr1.aspx', MyArgs, WinSettings);";

    str_Script += "if (MyArgs == null)";
    str_Script += "{";
    str_Script += "}";
    str_Script += "else";
    str_Script += "{";
    str_Script += "document.getElementById('TextBox1').value =MyArgs[0].toString();";
    str_Script += "}";
    str_Script += "}}";
    str_Script += "</script> ";
    this.Page.RegisterStartupScript("Reconnect", str_Script);

}

Please help me out to make it work again properly as it was working very fine earlier before chrome update. Please let me know any good alternative for this which will fix it.


回答1:


As you can read here, Window.showModalDialog() is deprecated and Chrome doesn't support it anymore from version 37 and has been completely removed from version 43.

Use Bootstrap Modal instead or, if too expensive to change, try this library, that is a window.showModalDialog polyfill




回答2:


We have this problem on many legacy asp applications. I found at least 3 different approaches but settled on something much simpler that I think is a possible answer to your issue. It works great to fix classic asp pages, but will work in a .Net environment as well. Here's the pseudo code of the approach:

In the calling form javascript:

var chrome_pop_up_window = null; //global for next few functions
function uploadChromeFinished(parameters) {
    //do something with parameters
    if(chrome_pop_up_window != null) {
        chrome_pop_up_window.close();
        chrome_pop_up_window = null;
    }
}
function OpenChild() {
    if(!window.showModalDialog)
         chrome_pop_up_window = window.open(url, "_blank", other_settings);
    else {
         var result = showModalDialog(...);
    }
}

Then in the child page, I have a document ready that knows whether to close the window modal or call the opener's function. The "opener" is the page that opened the pop up. For .net, I would recommend a post back that sets a hidden variable to let the page know it is finished.

if(document.getElementById("am_I_finished").value = 'true') {
      window.opener.uploadChromeFinished(parameters_if_needed);
else {
     window.dialogArguments.something = some_value_if_needed;
     window.returnValue = true; //or false         
     windlow.close();
}

Then end result is that the popup gets opened whether in Chrome or IE, and the child can communicate information back to the parent on close whether Chrome or IE, although in the case of Chrome, the parent is actually closing the child after it gets parameter values from the child. No plugins or json required.



来源:https://stackoverflow.com/questions/36500345/window-showmodaldialog-not-working-in-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!