2011/01/14

document.onstop

document 載入前 需要先 load 進一些東西
當然 是用 document.onload
相關文件 網路也很多

但是 有些動作 再等待載入中要show,
或是需要等到 document 其他物件都生成完全 才能動作怎辦?
*NOTE: IE-only !!
document.onstop = function() {
    try {
        if( document.readyState != "complete" ) {
                showLoadingDiv();
        } else {
                LoadComplete();
        }
    } catch( error ) {
        handleError( error );
    }
}
或用 <script language="javascript" defer> 去做推遲
document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
  if (this.readyState == "complete") {
    init(); // call the onload handler
  }
};



若有 jQuery 可用...

if (/WebKit/i.test(navigator.userAgent)) { // sniff
  var _timer = setInterval(function() {
    if (/loaded|complete/.test(document.readyState)) {
      clearInterval(_timer);
      init(); // call the onload handler
    }
  }, 10);
}

沒有留言:

張貼留言