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

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

接上篇,其它方法:
一、在IE中還可以在onreadystatechange事件里進行判斷
http://www.thefutureoftheweb.com/blog/adddomloadevent
這里有Jesse Skinner寫了一段獨立的腳本函數來解決各種瀏覽器的onload問題,。
http://img.jb51.NET/jslib/adddomloadevent.js
復制代碼 代碼如下:
/*
* (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 我們可以看到
復制代碼 代碼如下:
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/
復制代碼 代碼如下:
/*
*
* 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技術window.onload 加載完畢的問題及解決方案(下),轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 中文字幕a有搜索网站 | 9位美女厕所撒尿11分 | 国产成人在线播放视频 | 乱亲女H秽乱长久久久 | 成人网视频在线观看免费 | adc年龄确认大驾光临入口 | 亚洲国产精品一区二区动图 | 香蕉鱼视频观看在线视频下载 | 无码专区久久综合久综合字幕 | 小夫妻天天恶战 | 日本撒尿特写 | 国精一区二区AV在线观看网站 | 亚洲在线国产日韩欧美 | 超碰国产视频免费播放 | 久久99精品国产麻豆婷婷 | 人成午夜免费视频 | 99re在这里只有精品 | 免费啪视频观试看视频 | 手机在线观看你懂的 | 999久久久无码国产精蜜柚 | 大桥未久在线看 | 98久久人妻无码精品系列蜜桃 | 欧美精品亚洲精品日韩专区一 | 欧美九十老太另类 | 久久视频这里只精品99热在线 | 高清无码色大片中文 | 久久久久久天天夜夜天天 | 亚洲熟妇无码乱子AV电影 | 女生下面免费看 | 欧美精品成人久久网站 | 又粗又大又爽又黄的免费视频 | 久久久久青草大香线综合精品 | 野花香在线观看免费高清播放视频 | 国产亚洲精品久久久久 | 麻豆精品人妻一区二区三区蜜桃 | 久久在精品线影院精品国产 | 99久久精品国产国产毛片 | 无码成人AAAAA毛片含羞草 | 亚洲国产高清在线观看视频 | 嫩草影院永久在线一二三四 | 伊人久久大香线蕉观看 |