Dispatch event issue with IE



I want to dispatch the popstate event. The following code works in all browsers but IE:

dispatchEvent(window, makeEvent(popstate))’

In IE this returns with the error “Object does not support this action”.

I found a Javascript solution for this problem, but wonder how to translate that into Reason.

if(typeof(Event) === 'function') {
    var event = new Event('submit');
    var event = document.createEvent('Event');
    event.initEvent('submit', true, true);



Is there a chance someone could give me a hint on how to migrate this code to Reason?

type evt;

[@bs.val] external eventFunction: 'a = "Event";
[@bs.new] external makeEvent: string => evt = "Event"; 
switch (Js.Types.classify(eventFunction)) {
  | Js.Types.JSUndefined => { failwith("Handle ie8")}
  | _ => makeEvent("submit")

Playground link

This will get you most of the way there


That helped. Thank you.

To catch IE11 I had to use Js.Types.JSObject(_) instead of Js.Types.JSUndefined.

I implemented the IE part like this:

[@bs.val] [@bs.scope "document"]
external createEvent : string => Dom.event = "createEvent";

external initEvent :
  (Dom.event, [@bs.string] [ | `submit], Js.boolean, Js.boolean) => unit =
let ev = createEvent("Event");
initEvent(ev, `submit, Js.true_, Js.true_);