function addListener(elem, type, fn, capturingPhase) { if (elem.addEventListener) { elem.addEventListener(type, fn, capturingPhase); } else if (elem.attachEvent) { // IE8...IE6. Bubbling only elem.attachEvent("on" + type, function() { return fn.call(elem, window.event); }); } else { // IE5-. Bubbling only elem["on" + type] = fn; } }