admin管理员组文章数量:1292737
My project was totally involved in asp, We are working on browser patibility issues,
window.showModalDialog
is not working in chrome please help me with any replacement, other thanwindow.open
My project was totally involved in asp, We are working on browser patibility issues,
Share Improve this question edited Apr 29, 2015 at 6:04 Kar Reddy asked Apr 29, 2015 at 5:39 Kar ReddyKar Reddy 1681 gold badge1 silver badge12 bronze badges
window.showModalDialog
is not working in chrome please help me with any replacement, other thanwindow.open
3 Answers
Reset to default 2You could use polyfills to resolve this issue. 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()
<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. 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.
<script src="https://code.jquery./jquery-3.4.1.js"></script>
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);
本文标签: javascriptWindowshowModalDialog ReplacementStack Overflow
版权声明:本文标题:javascript - Window.showModalDialog Replacement - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741560622a2385423.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论