Last active
May 23, 2018 11:23
-
-
Save vmattos/7897274 to your computer and use it in GitHub Desktop.
attachEvent polyfill I made for my buddy @leandrooriente, who is nuts about IE. Now you can enjoy your Micro$oft event handlers everywhere! I'm a douchebag.
This file contains hidden or 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
(function(win){ | |
if(win.attachEvent) return; | |
var attachEvent = function(on, callback) { | |
var on = on.substring(2,on.length); | |
return this.addEventListener(on, callback); | |
} | |
win.Element.prototype.attachEvent = attachEvent; | |
})(window); |
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>attachEvent-polyfill Test</title> | |
</head> | |
<body> | |
<a id='btn-click' href="http://www.google.com">Turn me green</a> | |
<script src="polyfill.js"></script> | |
<script> | |
var btnClick = document.querySelector('#btn-click'); | |
btnClick.attachEvent('onclick', function(event){ | |
event.preventDefault(); | |
this.style.color = 'green'; | |
}); | |
</script> | |
</body> | |
</html> |
You don't want to use a attachEvent polyfill with IE7 either
if this makes you a douchebag, you're a very dear douchebag to me.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Beautiful, but i cant use querySelector with IE 7 =(