'domcontentloaded'에 해당되는 글 1건

  1. 2007/09/27 DOMContentLoaded revisited
hacking/web2007/09/27 11:48
크리에이티브 커먼즈 라이선스
Creative Commons License
DOMContentLoaded가 뭔지 모르신다면 신경끄셔도 무방한 아이템 되겠다.

그게 뭔지 아신다면... 그로 인한 고통도 자알 알고 계실터...
어처구니없는 해결책 하나 보시겠다:
(출처: http://javascript.nwbox.com/IEContentLoaded/ )
(function (){

//check IE's proprietary DOM members
if(!document.uniqueID && document.expando) return;

//you can create any tagName, even customTag like <document:ready />
var tempNode = document.createElement('document:ready');
try {
//see if it throws errors until after ondocumentready
tempNode.doScroll('left');

//call your function which catch window.onDocumentReady
alert('window.onDocumentReady()');

//relaese some memory, if possible
tempNode = null;

}catch (err){
setTimeout(arguments.callee, 0);
}

})();
해설을 덧붙이면: DOM이 완전히 로딩될때까지 계속 무대뽀로 DOM의 첫번째 노드를 scroll한다. DOM이 완전히 로드되기 전까지는 예외가 떨어지지만, DOM이 완전히 로드된 다음에는 (당연하게도)예외가 발생하지 않고 scoll된다(첫번째 노드가 align:right라면 OTL). 정말 개무식한 방법이지만... 유용하다. IE만쉐! 만쉐! lol
여기에 살을 약간 덧 붙이면 모든 브라우져를 위한 꽁수 완성:
(출처: http://webreflection.blogspot.com/2007/09/whats-wrong-with-new-iecontentloaded.html )
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");

});
애써 이해할려고 하지말고, 그냥 쓰셔도 무방하겠다. dojo의 addOnLoad를 이걸로 바꾸면 쓸만하겠다.
여기서도 세삼 느끼는 점은 IE KIN~


'hacking > web' 카테고리의 다른 글

prototype사용자를 위한 dojo 입문 (1)  (0) 2007/11/13
2007 Ajaxian.com Reader Survey 결과  (0) 2007/10/15
DOMContentLoaded revisited  (0) 2007/09/27
RIA 전성 시대? AJAX 독주 체제!  (2) 2007/09/22
dojo 1.0을 위한 grid 위젯은 TurboGrid  (0) 2007/09/17
SVG for All  (2) 2007/09/14
Posted by iolo