简体   繁体   English

Window.showModalDialog 替换

[英]Window.showModalDialog Replacement

My project was totally involved in asp.net, We are working on browser compatibility issues,我的项目完全涉及asp.net,我们正在研究浏览器兼容性问题,

window.showModalDialog is not working in chrome please help me with any replacement, other than window.open window.showModalDialog不能在 chrome 中工作,请帮助我进行任何替换,除了window.open

You could use polyfills to resolve this issue.你可以使用 polyfills 来解决这个问题。 Click here for more details点击这里了解更多详情

Another link that could help另一个可以提供帮助的链接

Hi if your concern is that u can edit the parent window even after opening the popup (Which was not the case with showModalDialog ), then u can use code something like this using window.open()嗨,如果您担心即使在打开弹出窗口后您也可以编辑父窗口showModalDialog 不是这种情况),那么您可以使用window.open() 使用类似这样的代码

<html>
<head>
<script type="text/javascript">

var popupWindow=null;

function child_open()
{ 
if(popupWindow && !popupWindow.closed)
  popupWindow.focus();
else
  popupWindow =window.open('(Any html file)',"_blank","directories=no, status=no, menubar=no, scrollbars=yes, resizable=no,width=600, height=280,top=200,left=200");

}
function parent_disable() {
 if(popupWindow && !popupWindow.closed)
   popupWindow.focus();
}
</script>
</head>
<body onFocus="parent_disable();" onclick="parent_disable();">
  <a href="javascript:child_open()">Click me</a>
</body>    
</html>

There is no real replacement for showModalDialog. 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.您可以使用 window.open 打开对话框子页面,然后使用 window.opener 更新父页面上的控件。 This would not work in the client javascript when waiting for a result value from the dialog subpage.当等待来自对话框子页面的结果值时,这在客户端 javascript 中不起作用。 The only way to create a sync call to a subpage is to use JQuery with Ajax.创建对子页面的同步调用的唯一方法是将 JQuery 与 Ajax 结合使用。

Make sure you include JQuery in the page head.确保在页面标题中包含 JQuery。 Note: need the full JQuery that contains the ajax functions.注意:需要包含 ajax 函数的完整 JQuery。

<script src="https://code.jquery.com/jquery-3.4.1.js"></script>

Then add a new function in the client javascript to make the Ajax call.然后在客户端 javascript 中添加一个新函数来进行 Ajax 调用。 Note the ajax function has to be set to async: false so the client javascript waits for a result.请注意,ajax 函数必须设置为 async: false 以便客户端 javascript 等待结果。

// -------------------------------------------------------------------------------------
    // 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.然后在 ASP 对话框子页面中添加以下 vbScript 代码来清除对话框页面并将响应转换为 JSON 格式。

' 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用新的 javascript 函数 GetJSONdlgResult 替换客户端 javascript 中的 showModalDialog 调用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM