Reputation: 921
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
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
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
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.
Upvotes: 4