admin管理员组

文章数量:1317914

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:

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./ticket/11127

Share Improve this question edited Aug 16, 2013 at 19:40 Irvin Dominin 31k9 gold badges80 silver badges113 bronze badges asked Aug 16, 2013 at 19:35 Kalvin KlienKalvin Klien 9211 gold badge14 silver badges33 bronze badges 3
  • Take a look here stackoverflow./questions/9769868/…, try to fix the code and eventually pull a request to the developers. – Irvin Dominin Commented Aug 16, 2013 at 19:39
  • You don't need to make a pull, you should use the jquery version to IE8/IE7 support. – Vinícius Moraes Commented Aug 20, 2013 at 19:13
  • "you should use the jquery version" - Doesn't work either. – Eirinn Commented May 23, 2014 at 13:23
Add a ment  | 

3 Answers 3

Reset to default 4

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/en-US/docs/Web/API/EventTarget.addEventListener?redirectlocale=en-US&redirectslug=DOM%2FEventTarget.addEventListener

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

Try it. https://github./egjs/hammerjs-patible

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

本文标签: javascriptHammerjs (IE8) Object doesn39t support property or method 39addEventListener39Stack Overflow