Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hammer.js (IE8)- Object doesn't support property or method 'addEventListener'

I'm using hammer.js for a touch menu for a site, and getting:

"Object doesn't support property or method 'addEventListener'" hammer.js, line 247 character 13

with IE8.

The actual code from hammer.js that is not working:

/**
 * simple addEventListener
 * @param   {HTMLElement}   element
 * @param   {String}        type
 * @param   {Function}      handler
 */
bindDom: function(element, type, handler) {
    var types = type.split(' ');
    for(var t=0; t<types.length; t++) {
        element.addEventListener(types[t], handler, false);
    }
},

Any idea how I can fix this?

Jquery used to have a similar issue: http://bugs.jquery.com/ticket/11127

like image 549
Kalvin Klien Avatar asked Aug 16 '13 19:08

Kalvin Klien


1 Answers

Starting from here: addEventListener not working in IE8

You can fix the code function by checking the definition of addEventListener like :

bindDom: function (element, type, handler) {
    var types = type.split(' ');
    for (var t = 0; t < types.length; t++) {
        if (!element.addEventListener) {
            element.attachEvent(types[t], handler);
        } else {
            element.addEventListener(types[t], handler, false);
        }
    }
},

if it works we can eventually pull a request to the developers.

Docs: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget.addEventListener?redirectlocale=en-US&redirectslug=DOM%2FEventTarget.addEventListener

like image 75
Irvin Dominin Avatar answered Nov 15 '22 07:11

Irvin Dominin