Event Constructor throws Object doesn’t support this action error in internet explorer

To use Event API on inter­net explorer, you will have to add the fol­low­ing poly­fill when your appli­ca­tion loads initially.

(function () {

  if ( typeof window.CustomEvent === "function" ) return false;

  function CustomEvent ( event, params ) {
    params = params || { bubbles: false, cancelable: false, detail: undefined };
    var evt = document.createEvent( 'CustomEvent' );
    evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
    return evt;
   }

  CustomEvent.prototype = window.Event.prototype;

  window.CustomEvent = CustomEvent;
})();

Once you add above poly­fill, in your app code instead of Event use CustomEvent. For example,

// var event = new Event("tooltip_shown", {'bubbles': true});
var event = new CustomEvent("tooltip_shown", {'bubbles': true});

Ref­er­ence


You may also like...