Skip to content

Instantly share code, notes, and snippets.

@elliotaplant
Created March 22, 2018 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elliotaplant/fb3f028500d09150eae36885d137844b to your computer and use it in GitHub Desktop.
Save elliotaplant/fb3f028500d09150eae36885d137844b to your computer and use it in GitHub Desktop.
How to add event listeners in Internet Explorer 9+
// From https://stackoverflow.com/questions/20180046/attachevent-doesnt-work-in-ie-8-0
// You can run some feature-checking code to check if the supported features exist:
if (window.addEventListener) {
// Check for addEventListener first, since IE9/10 have both,
// but you should use the standard over the deprecated IE-specific one
window.addEventListener('click', myFunc);
} else if (window.attachEvent) {
window.attachEvent('onclick', myFunc);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment