Posted here is an answer that instructs those who miss the old window.showModalDialog
JavaScript function to use the
<dialog>
element instead. I have used this along with the polyfill needed for IE and FF and it works. However, there is a noticeable lag introduced when using the polyfill that I would like to avoid for Chrome (not to mention there is a warning not to use the polyfill when browsers support it). How do I detect whether or not the dialog element is supported so I can leave out the polyfill processing? Specifically these lines:
var dialog = document.getElementById('<element id>');
dialogPolyfill.registerDialog(dialog);
The concept of feature detection The idea behind feature detection is that you can run a test to determine whether a feature is supported in the current browser, and then conditionally run code to provide an acceptable experience both in browsers that do support the feature, and browsers that don't.
A dialog is a box of content which is above the content of a page. The backdrop is something like a shadow behind an element which prohibits the interaction with the content behind it. Last but not least a modal is the combination of a dialog with a backdrop. Simply put: dialog + backdrop = modal.
The <dialog> tag defines a dialog box or subwindow. The <dialog> element makes it easy to create popup dialogs and modals on a web page.
You could write a simple test like this:
if (typeof HTMLDialogElement === 'function') {
/** yep */
} else {
/** nope */
}
Try console.log(typeof window.showModalDialog === 'undefined')
if (typeof window.showModalDialog === 'undefined') {
console.log('No. ');
} else {
console.log('Yes! ');
}
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