首頁  >  文章  >  web前端  >  谷歌showModalDialog()方法不相容於出現對話視窗的解決方案_javascript技巧

谷歌showModalDialog()方法不相容於出現對話視窗的解決方案_javascript技巧

WBOY
WBOY原創
2016-05-16 15:15:411306瀏覽

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事件進行呼叫方法就行

以上為大家介紹了GoogleshowModalDialog()方法不相容出現對話視窗的問題分析及解決方法,希望對大家有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn