Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

showModalDialog alternative?

I'm managing an old site that's riddled with popup windows. They're quite annoying because they keep getting lost behind the main window. I'm slowly moving them over to over to a modern 'lightbox' but it's a slow and tedious process because all these popups contain forms and the validation is done server-side, which means I need to be able to submit the form and then re-render it if there's an error without breaking the whole page.

I just discovered there's a window.showDialogBox which works perfectly in Firefox (prevents you from clicking the main page until you close the dialog), but Chrome has already deprecated it, and IE only half supports it.

So, is there anything I can replace window.open with in the mean time to provide a better user experience, without re-writing every form to send and receive JSON via XHR?

like image 854
mpen Avatar asked Jun 25 '14 04:06

mpen


People also ask

What is the replacement for showModalDialog?

There is no real replacement for showModalDialog. You could use window. open to open the dialog subpage and then use the window.

Why is showModalDialog deprecated?

showModalDialog() Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes.

How do I use Windows showModalDialog on Chrome?

To use the showModalDialog method you simply call it with a URL. window. showModalDialog('http://google.com'); This will open up a modal dialog with Google loaded in it.

What is window dialogArguments?

The dialogArguments property returns the parameters that were passed into the window. showModalDialog() method. This lets you determine what parameters were specified when the modal dialog was created.


2 Answers

You can use my showModalDialog polyfill using the brand new modal <dialog> element, which works in the latest Google Chrome. A <dialog> polyfill for older browsers is here.

like image 69
niutech Avatar answered Sep 16 '22 16:09

niutech


You can use different codes for different browsers, like this:

if(navigator.userAgent.indexOf("MSIE") != -1){     //If the browser is IE
     //Code for IE
}
else if(navigator.vendor == "Firefox"){            //If the browser is Firefox
     //Code for Firefox
}
else if(navigator.vendor == "Google Inc."){        //If the browser is Chrome
     //Code for Chrome
}

For IE, showModalDialog works just fine and it prevents you from clicking the main page until you close the dialog.
For Firefox, you can use, as you said, showDialogBox.
For Chrome, you can use the thing that niutech suggests.

Otherwise, if you use window.open, all the popup windows will be in the task bar so if they are hidden behind the window, just click on them in the task bar to make them visible.

like image 37
Donald Duck Avatar answered Sep 17 '22 16:09

Donald Duck