Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event creation illegal constructor on stock Android Browser < 5.0 #1286

Closed
mirkoschmidt opened this issue Feb 8, 2016 · 1 comment
Closed
Assignees

Comments

@mirkoschmidt
Copy link

On the built-in Android browser on Android versions < 5.0, the select box throws a js error:
**
Uncaught Type Error: Illegal constructor**

The culprit is in line 136:

event = new Event(eventName, {
          bubbles: true
        });

My propsed solution would be to wrap it inside a try catch, so the old-fashioned way could be triggered:

try {
          event = new Event(eventName, {
            bubbles: true
          });
        } catch(e){
          event = document.createEvent('Event');
          event.initEvent(eventName, true, false);
        }
@shaarman
Copy link

shaarman commented Sep 3, 2016

Good find! Based on that, here's a workaround you can add to your js so you do not have to change the sourcecode (and can keep on using the CDN).
Just add it in your $(document).ready.

  var selects = $("select");
  if (selects.length > 0 && selects[0].dispatchEvent) {
    if (typeof Event === "function") {
      try {
        event = new Event("change", { bubbles: true });
      } catch(e) {
        // reduce the original function to the working version
        $.fn.triggerNative = function (eventName) {
          var el = this[0];
          var event = document.createEvent("Event");
          event.initEvent(eventName, true, false);
          el.dispatchEvent(event);
        };
      }
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants