天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

window.onload 加載完畢的問題及解決方案(下)

接上篇,其它方法:
一、在IE中還可以在onreadystatechange事件里進(jìn)行判斷
http://www.thefutureoftheweb.com/blog/adddomloadevent
這里有Jesse Skinner寫了一段獨(dú)立的腳本函數(shù)來解決各種瀏覽器的onload問題,。
http://img.jb51.NET/jslib/adddomloadevent.js
復(fù)制代碼 代碼如下:
/*
* (c)2006 Jesse Skinner/Dean Edwards/Matthias Miller/John Resig
* Special thanks to Dan Webb's domready.js Prototype extension
* and Simon Willison's addLoadEvent
*
* For more info, see:
* http://www.thefutureoftheweb.com/blog/adddomloadevent
* http://dean.edwards.name/weblog/2006/06/again/
* http://www.vivabit.com/bollocks/2006/06/21/a-dom-ready-extension-for-prototype
* http://simon.incutio.com/archive/2004/05/26/addLoadEvent
*
*
* To use: call addDOMLoadEvent one or more times with functions, ie:
*
* function something() {
* // do something
* }
* addDOMLoadEvent(something);
*
* addDOMLoadEvent(function() {
* // do other stuff
* });
*
*/

addDOMLoadEvent = (function(){
// create event function stack
var load_events = [],
load_timer,
script,
done,
exec,
old_onload,
init = function () {
done = true;

// kill the timer
clearInterval(load_timer);

// execute each function in the stack in the order they were added
while (exec = load_events.shift())
exec();

if (script) script.onreadystatechange = '';
};

return function (func) {
// if the init function was already ran, just run this function now and stop
if (done) return func();

if (!load_events[0]) {
// for Mozilla/Opera9
if (document.addEventListener)
document.addEventListener("DOMContentLoaded", init, false);

// for InterNET Explorer
/*@cc_on @*/
/*@if (@_win32)
document.write("<script id=__ie_onload defer src="http://0" src="http://0"><//scr"+"ipt>");
script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
if (this.readyState == "complete")
init(); // call the onload handler
};
/*@end @*/

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

// for other browsers set the window.onload, but also execute the old window.onload
old_onload = window.onload;
window.onload = function() {
init();
if (old_onload) old_onload();
};
}

load_events.push(func);
}
})();

二、另外還有在IE中的doScroll的,這是種方法只對IE有作用,而且它是一種hack方法。

在MSDN:About Element Behaviors 我們可以看到
復(fù)制代碼 代碼如下:
When the ondocumentready event fires, the document has been completely parsed and built. Initialization code should be placed here if the component needs to navigate the primary document structure. The ondocumentready event notifies the component that the entire page is loaded, and it fires immediately before the onload event fires in the primary document.
A few methods, such as doScroll, require the primary document to be completely loaded. If these methods are part of an initialization function, they should be handled when the ondocumentready event fires.

http://Javascript.nwbox.com/IEContentLoaded/
復(fù)制代碼 代碼如下:
/*
*
* IEContentLoaded.js
*
* Author: Diego Perini (diego.perini at gmail.com) NWBOX S.r.l.
* Summary: DOMContentLoaded emulation for IE browsers
* Updated: 05/10/2007
* License: GPL/CC
* Version: TBD
*
*/

// @w    window reference
// @fn    function reference
function IEContentLoaded (w, fn) {
    var d = w.document, done = false,
    // only fire once
    init = function () {
        if (!done) {
            done = true;
            fn();
        }
    };
    // polling for no errors
    (function () {
        try {
            // throws errors until after ondocumentready
            d.documentElement.doScroll('left');
        } catch (e) {
            setTimeout(arguments.callee, 50);
            return;
        }
        // no errors, fire
        init();
    })();
    // trying to always fire before onload
    d.onreadystatechange = function() {
        if (d.readyState == 'complete') {
            d.onreadystatechange = null;
            init();
        }
    };
}

在jQuery的源碼中,針對Mozilla, Opera 和webkit用的是DOMContentLoaded,也就是上一篇中第一種;

而對IE用的是doScroll的方法。

JavaScript技術(shù)window.onload 加載完畢的問題及解決方案(下),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 国产69精品久久久熟女 | 亚洲m男在线中文字幕 | 久久爱狠狠综合网 | 九九这里有精品 | 久久国产香蕉 | 十二月综合缴缴情 | 成人a毛片久久免费播放 | 免费观看国产视频 | 久久视频精品3线视频在线观看 | 麻花传媒XK在线观看 | 国产精品久久久久影院色 | 精品一区二区三区AV天堂 | 日韩黄色免费 | 久久精品国产免费 | 久久全国免费观看视频 | 在线va无卡无码高清 | 国精产品砖一区二区三区糖心 | 亚洲精品久久久久AV无码林星阑 | 青青草在线视频 | 国产在线视频一区二区不卡 | 欧美亚洲韩日午夜 | 性盈盈剧场 | 亚洲免费在线播放 | 日韩亚洲视频一区二区三区 | 亚洲欧洲自拍偷拍 | 精品无码三级在线观看视频 | 在线自拍亚洲视频欧美 | 最近的2019中文字幕HD | 古代荡乳尤物H妓女调教 | 国产精品你懂的在线播放 | 草草久久久无码国产专区全集观看 | 美女穿丝袜被狂躁动态图 | 麻豆国产96在线日韩麻豆 | 精品国产成人AV在线看 | 久久国产乱子伦免费精品 | 午夜熟女插插XX免费视频 | 欧美精品成人a多人在线观看 | 美女激清床上戏大全 | 中文无码熟妇人妻AV在线 | 亚洲AV日韩AV欧美在线观看网 | 国产亚洲精品久久久久久一区二区 |