JS showModalDialog不能在Chrome中作为模式工作 [英] JS showModalDialog not working in chrome as modal

查看:234
本文介绍了JS showModalDialog不能在Chrome中作为模式工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用 showModalDialog(),以供用户查看来自不同来源的文章作为模式弹出窗口。

它可以在FF和IE中正常工作,但是在Chrome中它并不像模态一样,我仍然可以继续使用父窗口并单击其中的任何元素。



我想让它和IE和FF一样。



我看了几个解决方法

1)在父窗口中设置 onfocus 事件,并再次将焦点放在它上面。

 < script type =text / javascript> 
setInterval(checkFocus,10);
var mywindow;
函数openModal(){
var a = new Array;
a [0] = 1;
a [1] = 4;
mywindow = window.showModalDialog(myurl,
a,dialogwidth:1000; dialogheight:700; resizable:yes; center:yes;);


函数checkFocus(){
if(mywindow!= null&&mywindow!= undefined){
if(window.focus){
mywindow.focus();
}
}
}
< / script>

但这似乎并不像预期的那样工作。

2)在子窗口中设置 onblur 事件,重新集中自己。

我已经从一些在线资源中读到这个解决方案。我可以应用此解决方案,如果只有子窗口是从我的域名定制页面,但作为我的子窗口可以是任何 url 从任何它不适用于我的情况。



我需要使它工作,任何人都可以在此建议我吗?

解决方案

Chrome在实施过程中存在严重的错误。最重要的是Chrome浏览器显示的窗口不是模式(请参阅铬错误#16045 ),这意味着用户可以在处理模态对话框之前与原始窗口进行交互。


I am using showModalDialog() in my application, for user to view articles from different sources as modal popup.

It work fine with FF and IE, but in chrome it's not behaving as modal, I can still go on parent window and click on any element in it.

I wanted to make it work same as IE and FF.

I have looked at few work-around

1) set onfocus event on parent window, and focus child again on it.

     <script type="text/javascript">
        setInterval(checkFocus, 10);
        var mywindow;
        function openModal() {
            var a = new Array;
            a[0] = 1;
            a[1] = 4;
            mywindow = window.showModalDialog(myurl,
      a, "dialogwidth: 1000; dialogheight: 700; resizable: yes;center : yes;");
        }

        function checkFocus() {
            if (mywindow != null && mywindow != undefined) {
                if (window.focus) {
                    mywindow.focus();
                }
            }
        }
      </script>

but this is not seems to work as expected.

2) set onblur event on child window, to focus itself again

this solution i have read from some online sources. i can apply this solution if only child window is customized page from on my domain only , but as my child window can be any url from any domain It is not applicable in my case.

I need to make it work , can anybody suggest me on this??

解决方案

Chrome has serious bugs with its implementation. Most importantly the window Chrome displays isn’t modal (see Chromium bug #16045), meaning, the user is able to interact with the original window before dealing with the modal dialog.

这篇关于JS showModalDialog不能在Chrome中作为模式工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆