Posted By

nerdfiles on 03/01/09


Tagged

javascript ie6 addeventlistener attachevent addevent ie7


Versions (?)

"addEventListener" cross-browser fix


 / Published in: JavaScript
 

Not my solution, see "Catching Up with addEvent()": http://particletree.com/files/designersguide/AddEventHistory.pdf

  1. function addEvent(obj,type,fn) {
  2.  
  3. if (obj.addEventListener) {
  4. obj.addEventListener(type,fn,false);
  5. return true;
  6. } else if (obj.attachEvent) {
  7. obj['e'+type+fn] = fn;
  8. obj[type+fn] = function() { obj['e'+type+fn]( window.event );}
  9. var r = obj.attachEvent('on'+type, obj[type+fn]);
  10. return r;
  11. } else {
  12. obj['on'+type] = fn;
  13. return true;
  14. }
  15.  
  16. }

Report this snippet  

You need to login to post a comment.