>  기사  >  웹 프론트엔드  >  대화 상자 창이 나타날 때 Google showModalDialog() 메서드의 비호환성에 대한 해결 방법_javascript 기술

대화 상자 창이 나타날 때 Google showModalDialog() 메서드의 비호환성에 대한 해결 방법_javascript 기술

WBOY
WBOY원래의
2016-05-16 15:15:411306검색

테스트에서 showModalDialog는 IE와 Firefox에서 정상적으로 실행되지만 Google에서는 클릭 후 응답이 없습니다. 온라인에서 찾아보니 Google Chrome이 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 이벤트를 사용하여 메소드를 호출하면 됩니다.

위에서는 Google의 showModalDialog() 메서드에 나타나는 호환되지 않는 대화 상자 문제에 대한 분석 및 해결 방법을 소개했습니다.

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.