The code is mainly transferred from the network, and the source is unknown. I made a slight modification to the code.
Code
(Function (){
VaR addevent = function (OBJ, type, FN ){
If (obj. addeventlistener)
OBJ. addeventlistener (type, FN, false );
Else if (obj. attachevent ){
OBJ ["E" + Type + FN] = FN;
OBJ. attachevent ("On" + type, function (){
OBJ ["E" + Type + FN] ();
});
}
};
VaR onready = function (loadevent, waitforimages ){
If (waitforimages ){
Return addevent (window, 'load', loadevent );
}
VaR init = function (){
If (arguments. callee. Done) return;
Arguments. callee. Done = true;
Loadevent. Apply (document, arguments );
};
If (! + "\ V1 "){
If (window. Self = Window. Top ){
(Function (){
Try {
Document.doc umentelement. doscroll ("Left ");
} Catch (e ){
SetTimeout (arguments. callee, 0 );
Return;
}
Init ();
})();
} Else {
Document. attachevent ("onreadystatechange", function (){
If (document. readystate = "complete "){
Document. detachevent ("onreadystatechange", arguments. callee );
Init ();
}
});
}
} Else {
Document. addeventlistener ("domcontentloaded", function (){
Document. removeeventlistener ("domcontentloaded", arguments. callee, false );
Init ();
}, False );
}
Return true;
}
If (! Window. onready ){
Window ["onready"] = onready;
}
})();
Load the js code first.
Multiple onready calls can be made on the same page:
Code
<HTML>
<Head>
Reference JS
<Script/*... 1 .. */>
Onready (function () {/* Do something */});
</SCRIPT>
</Head>
<Body>
......
<Script/*... 2 .. */>
Onready (function () {/* Do something */});
</SCRIPT>
</Body>
</Html>