We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

mifly on 03/12/08


Tagged

javascript


Versions (?)


Who likes this?

2 people have marked this snippet as a favorite

SpinZ
rafael


cross browser addEvenlistener


Published in: JavaScript 


URL: http://www.digital-web.com/articles/seven_javascript_techniques/

  1. var addListener = function() {
  2. if ( window.addEventListener ) {
  3. return function(el, type, fn) {
  4. el.addEventListener(type, fn, false);
  5. };
  6. } else if ( window.attachEvent ) {
  7. return function(el, type, fn) {
  8. var f = function() {
  9. fn.call(el, window.event);
  10. };
  11. el.attachEvent('on'+type, f);
  12. };
  13. } else {
  14. return function(el, type, fn) {
  15. element['on'+type] = fn;
  16. }
  17. }
  18. }();

Report this snippet 

You need to login to post a comment.