Last active
September 29, 2017 02:04
-
-
Save koreapyj/c7c0b8c7e5b4bff929707f939cf3da51 to your computer and use it in GitHub Desktop.
DOM을 다룰 수 있게 될 때 이벤트를 발생시킵니다. (cross browser)
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
function onDOMReady(listener) { | |
if(document.readyState) switch(document.readyState) { | |
case 'complete': | |
listener(); | |
break; | |
case 'interactive': | |
/* "interactive" in IE 9 is quite different - we can't handle DOM elements at this time */ | |
if(!(__MSIE__ = navigator.appVersion.match(/MSIE ([0-9]+\.[0-9]+)/)) || __MSIE__[1] > 9) { | |
listener(); | |
break; | |
} | |
default: | |
document.addEventListener('load', listener); | |
document.addEventListener('DOMContentLoaded', listener); | |
} | |
else { | |
// browser seems like way too old (ie < 8.0) - time to give up | |
throw 'YourMother: Too old browser!!!'; | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment