Window.showModalDialog Replacement

后端 未结 3 2029
一个人的身影
一个人的身影 2021-01-15 09:18

My project was totally involved in asp.net, We are working on browser compatibility issues,

window.showModalDialog is not working in chr

3条回答
  •  情歌与酒
    2021-01-15 09:39

    There is no real replacement for showModalDialog. You could use window.open to open the dialog subpage and then use the window.opener to update the controls on the parent page. This would not work in the client javascript when waiting for a result value from the dialog subpage. The only way to create a sync call to a subpage is to use JQuery with Ajax.

    Make sure you include JQuery in the page head. Note: need the full JQuery that contains the ajax functions.

    
    

    Then add a new function in the client javascript to make the Ajax call. Note the ajax function has to be set to async: false so the client javascript waits for a result.

    // -------------------------------------------------------------------------------------
        // Name: GetJSONdlgResult
        // Description: Ajax get request to the dialog Subpage to replace ShowModalDialog function.            
        //              Uri should already have all the parameters needed
        //              dialog SubPage will need the following code added to the final ASP vbscript function:
        //              ------------------------------------------------------------------------
        //              ' Clear whatever is currently on the page
        //              Response.Clear
        //              ' build the JSON Results from the sErrMsg variable
        //              Dim JSON_Results 
        //              JSON_Results = "{" & chr(34) & "returnValue" & chr(34) & ":" & chr(34) & sErrMsg & chr(34) & "}"
        //              ' Setup the JSON response header
        //              Response.ContentType = "application/json"
        //              ' Write it to the response and end it
        //              Response.Write JSON_Results
        //              Response.Flush
        //              Response.End
        // -------------------------------------------------------------------------------------
        function GetJSONdlgResult(strUrl) {
            var strResult = "Fail";
            try {
                var Request = $.ajax({
                    url: strUrl,
                    dataType: "json",
                    type: "get",
                    async: false, // async must be false so the javascript function waits for the subpage result like ShowModalDialog 
                    success: function (data) {
                        // JSON object from the ajax call. 
                        strResult = data.returnValue; // This could be any JSON result returned from the subpage
                    }
                });
            }
            catch (err) {
                alert(err);
            }
            return strResult
        }  
    

    Then add the following vbScript Code in the ASP dialog subpage to clear the dialog page and convert the response to JSON format.

    ' Clear whatever is currently on the page
    Response.Clear
    ' build the JSON Results from the sErrMsg ASP Server variable
    Dim JSON_Results 
    JSON_Results = "{" & chr(34) & "returnValue" & chr(34) & ":" & chr(34) & sErrMsg & chr(34) & "}"
    ' Setup the JSON response header
    Response.ContentType = "application/json"
    ' Write it to the response and end it
    Response.Write JSON_Results
    Response.Flush
    Response.End
    

    Replace the showModalDialog calls in the client javascript with the new javascript function GetJSONdlgResult

    //var sRetValue = window.showModalDialog(sURL);
    var sRetValue = GetJSONdlgResult(sURL);
    

提交回复
热议问题