Created
March 15, 2012 14:22
-
-
Save jCrip/2044435 to your computer and use it in GitHub Desktop.
Modern Event Handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
/** | |
* Attach an event handler on a given Node taking care of Browsers Differences | |
* @param {Object} node | |
* @param {String} type | |
* @param {Function} fn | |
* @param {Boolean} capture | |
*/ | |
function addEventHandler(node,type,fn , capture){ | |
if(typeof window.event !== "undefined"){ | |
/* Internet Explorer way */ | |
node.attachEvent( "on" + type, fn ); | |
} else { | |
/* FF & Other Browsers */ | |
node.addEventListener( type, fn , capture ); | |
} | |
} | |
/* Example */ | |
addEventHandler(window,"load",function(){ | |
alert("The page was loaded"); | |
},true) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment