中文字幕日韩一区二区_国产一区二区av_国产毛片av_久久久久国产一区_色婷婷电影_国产一区二区精品

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

接上篇,其它方法:
一、在IE中還可以在onreadystatechange事件里進(jìn)行判斷
http://www.thefutureoftheweb.com/blog/adddomloadevent
這里有Jesse Skinner寫了一段獨(dú)立的腳本函數(shù)來(lái)解決各種瀏覽器的onload問(wèn)題,。
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的,這是種方法只對(duì)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的源碼中,針對(duì)Mozilla, Opera 和webkit用的是DOMContentLoaded,也就是上一篇中第一種;

而對(duì)IE用的是doScroll的方法。

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

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

主站蜘蛛池模板: 亚洲乱码一区二区三区在线观看 | 亚洲小视频 | 国产1区在线 | 日本一区二区高清不卡 | 成人一区在线观看 | 亚洲欧美中文日韩在线 | 四虎影院在线免费观看 | 日日人人| 91亚洲一区 | 欧美日韩国产一区二区三区 | 乱一性一乱一交一视频a∨ 色爱av | 国产高清精品一区二区三区 | 羞羞色在线观看 | 亚洲国产一区二区三区在线观看 | 美女爽到呻吟久久久久 | 日韩精品激情 | 激情五月婷婷综合 | 日韩成人在线看 | 国产精品无码久久久久 | 欧美色综合 | 亚洲精品www久久久久久广东 | 国产精品久久久久久妇女6080 | 国产精品久久久久久久久久久久冷 | 精品国产乱码久久久久久牛牛 | 国产精品毛片一区二区在线看 | 狠狠干av | 成人小视频在线观看 | 91久久精品一区二区二区 | 秋霞a级毛片在线看 | 99国内精品久久久久久久 | 国产精品特级片 | 中文字幕在线看第二 | www312aⅴ欧美在线看 | 国产精品视频免费观看 | 久久久久久免费精品一区二区三区 | 欧美高清一级片 | 精品久久国产 | 日日骚av | 日韩欧美一区二区三区四区 | 黄色日批视频 | 国产一区二区精品在线观看 |