JS showModalDialog not working in chrome as modal

meghana picture meghana · Jan 18, 2013 · Viewed 8.1k times · Source

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

Answer

axel.michel picture axel.michel · Jan 18, 2013

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.