Hammer.js (IE8) - the object does not support the property or method 'addEventListener'

I use hammer.js for the touch menu for the site and get:

"The object does not support the property or method 'addEventListener'" hammer.js, line 247 character 13

with IE8.

Actual code from hammer.js that doesn't work:

/** * 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 had a similar problem: http://bugs.jquery.com/ticket/11127

+6
source share
3 answers

From now on: addEventListener does not work in IE8

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

 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 end up pulling a request to the developers.

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

+4
source

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

0
source

Give it a try. 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> 
0
source

Source: https://habr.com/ru/post/951911/


All Articles