DOM onReadyの別の実装

ソース: webreflection.blogspot.com

ソリューションの分析に基づいて、Andrea Giammarchiは美しいクロスブラウザオプションを提案しました...


レート:
onReady = (function(ie){
var d = document;
return ie ? function(c){
var n = d.firstChild,
f = function(){
try{
c(n.doScroll('left'))
}catch(e){
setTimeout(f, 10)
}
}; f()
} :
/webkit|safari|khtml/i.test(navigator.userAgent) ? function(c){
var f = function(){
/loaded|complete/.test(d.readyState) ? c() : setTimeout(f, 10)
}; f()
} :
function(c){
d.addEventListener("DOMContentLoaded", c, false);
}
})(/*@cc_on 1@*/);

onReady(function(){
alert("Hello DOM");
});


Source: https://habr.com/ru/post/J14481/


All Articles