JS showModalDialog not working in chrome as modal

旧时模样 提交于 2019-12-08 09:19:36

问题


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??


回答1:


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.



来源:https://stackoverflow.com/questions/14399127/js-showmodaldialog-not-working-in-chrome-as-modal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!