Skip to content Skip to sidebar Skip to footer

If EventConstructor Is Not A Constructor, How Should I Create The Event?

I'm following MDN guide and trying to create an event: MDN guide for creating events var jGp = new Object(); ... jGp.evt = new Object(); jGp.evt.erro = new Event('jGp_evtErro'); T

Solution 1:

I ran into this too on Safari, I used a try/catch statement in order to use the non-deprecated constructor whenever possible, but fail into the old way if necessary.

jGp.evt = new Object();
try {
  jGp.evt.erro = new Event("jGp_evtErro");
}
catch (e) {
  jGp.evt.erro = document.createEvent('Event');
  jGp.evt.erro.initEvent("jGp_evtErro", true, true);
}

Post a Comment for "If EventConstructor Is Not A Constructor, How Should I Create The Event?"