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()方法不兼容出現對話窗口的問題分析及解決辦法,希望對大家有所幫助。