Insert Function Only If It Doesn’t Exist

Asked

Viewed 55 times

3

The "window.showModalDialog" function exists in some versions of IE, but does not exist in Chrome, I would like to insert it if it does not exist. How can I do that?

window.showModalDialog = function (arg1, arg2, arg3) { 
//Minha função
}

1 answer

3


This functionality is not standardized, is deprecated, and should be avoided.

I think you pose different questions here, and interesting to separate.

How/when to apply a polyfill

You can detect if the function exists and if it does not exist apply a function of yours with similar behavior. Something like:

if (!window.showModalDialog) window.showModalDialog = function(){
    // etc ...

How to play this feature (ie how to create a polyfill for this method)?

That exists now and you can find it on Github here: https://github.com/niutech/showModalDialog

TO MDN also points out to that repository you have a demo here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.