Kalvin Klien
Kalvin Klien

Reputation: 921

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

Upvotes: 6

Views: 7998

Answers (3)

mixed
mixed

Reputation: 1

Try it. https://github.com/egjs/hammerjs-compatible

<!--[if IE 8]>
<script type="text/javascript" src="../dist/hammerjs.compatible.js"></script> <- like this.
<![endif]-->
<script src="../bower_components/hammer.js/hammer.js"></script>

Upvotes: 0

Vin&#237;cius Moraes
Vin&#237;cius Moraes

Reputation: 3516

If you need support for IE8 or IE7 you should use the jquery version of Hammer plugin. You can download it here.

Upvotes: 0

Irvin Dominin
Irvin Dominin

Reputation: 30993

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

Upvotes: 4

Related Questions