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?
There is no real replacement for showModalDialog. You could use window. open to open the dialog subpage and then use the window.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With