谷歌showModalDialog()方法不兼容出现对话窗口的解决办法

(编辑:jimmy 日期: 2024/10/5 浏览:2)

showModalDialog,在测试中,IE,Firefox中正常运行,但是在google中,点击后没什么反应,在网上看了一下,谷歌浏览器不支持showModalDialog模态对话框和无法返回returnValue,得到了一个解决办法

<script type="text/javascript">
//开启模式窗口
function showMyModal() {
var url = "SelectUser.aspx";
//传入参数示例
var modalReturnValue = myShowModalDialog(url, window, 300, 500);
//alert(modalReturnValue.name);
//窗口关闭后执行某些方法
//TODO sth
}
//弹出框google Chrome执行的是open
function myShowModalDialog(url, args, width, height) {
var tempReturnValue;
if (navigator.userAgent.indexOf("Chrome") > 0) {
var paramsChrome = 'height=' + height + ', width=' + width + ', top=' + (((window.screen.height - height) / 2) - 50) +
',left=' + ((window.screen.width - width) / 2) + ',toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no';
window.open(url, "newwindow", paramsChrome);
}
else {
var params = 'dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;status:no;dialogLeft:'
+ ((window.screen.width - width) / 2) + 'px;dialogTop:' + (((window.screen.height - height) / 2) - 50) + 'px;';
tempReturnValue = window.showModalDialog(url, args, params);
}
return tempReturnValue;
}
</script> 

最后想要点击就可以出现对话框就行,只需要使用onclick事件进行调用方法就行

以上给大家介绍了谷歌showModalDialog()方法不兼容出现对话窗口的问题分析及解决办法,希望对大家有所帮助。

一句话新闻

微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。