Posted By

mifly on 03/12/08


Tagged

javascript


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

SpinZ
rafael
wirenaught


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.