Copy codeThe Code is as follows:
// 163 AJAX Tab
// Update 2006.10.18
// Added the mouse latency sensing feature.
// Update 2006.10.8
// The href attribute of the tag retains the original HTML function. Add the URL attribute to the AJAX Load path.
// Update 2006.10.11
// Fixed IE5.0 undefined error and added Script Error Blocking.
Var Browser = new Object ();
Browser. isMozilla = (typeof document. implementation! = 'Undefined') & (typeof document. implementation. createDocument! = 'Undefined') & (typeof HTMLDocument! = 'Undefined ');
Browser. isIE = window. ActiveXObject? True: false;
Browser. isFirefox = (navigator. userAgent. toLowerCase (). indexOf ("firefox ")! =-1 );
Browser. isOpera = (navigator. userAgent. toLowerCase (). indexOf ("opera ")! =-1 );
If (Browser. isFirefox) {// entend Event Mod for FireFox
ExtendEventObject ();
}
Function extendEventObject (){
Event. prototype. _ defineGetter _ ("srcElement", function (){
Var node = this.tar get;
While (node. nodeType! = 1) node = node. parentNode;
Return node;
});
Event. prototype. _ defineGetter _ ("fromElement", function (){
Var node;
If (this. type = "mouseover ")
Node = this. relatedTarget;
Else if (this. type = "mouseout ")
Node = this.tar get;
If (! Node) return;
While (node. nodeType! = 1) node = node. parentNode;
Return node;
});
Event. prototype. _ defineGetter _ ("toElement", function (){
Var node;
If (this. type = "mouseout ")
Node = this. relatedTarget;
Else if (this. type = "mouseover ")
Node = this.tar get;
If (! Node) return;
While (node. nodeType! = 1) node = node. parentNode;
Return node;
});
}
Function IsChild (cNode, pNode ){
While (cNode! = Null ){
CNode = cNode. parentNode;
If (cNode = pNode) return true;
}
Return false;
}
Var ajccache = new Object ();
Var waitInterval;
Var tempref;
Var MouseDelayTime = 150; // The mouse sensing latency is 300 milliseconds.
Function getTBprefixName (str, sta ){
If (str. indexOf ("active ")! =-1 | str. indexOf ("normal ")! =-1) str = str. substr (6 );
Else if (str. indexOf ("over ")! =-1) str = str. substr (4 );
Else str = "";
Return sta + str;
}
Function startajaxtabs (){
For (var I = 0; I <arguments. length; I ++)
{
Var ulobj = document. getElementById (arguments [I]);
Ulist = ulobj. getElementsByTagName ("li ");
For (var j = 0; j <ulist. length; j ++)
{
Var thelist = ulist [j];
If (thelist. parentNode. parentNode! = Ulobj) continue; // only the first layer of li is valid fixed 2006.9.29
Var ulistlink = thelist. getElementsByTagName ("a") [0];
Var ulistlinkurl = ulistlink. getAttribute ("urn ");
Var ulistlinktarget = ulistlink. getAttribute ("rel ");
Thelist. setActive = function (bactive ){
If (bactive ){
This. status = "active ";
This. className = getTBprefixName (this. className, "active ");
} Else {
This. status = "normal ";
This. className = getTBprefixName (this. className, "normal ");
}
}
Thelist. LoadTab = function (){
This. setActive (true );
This. parentNode. parentNode. activetab. setActive (false );
This. parentNode. parentNode. activetab = this;
Var ulistlink = this. getElementsByTagName ("a") [0];
LoadAJAXTab (ulistlink. getAttribute ("urn"), ulistlink. getAttribute ("rel "));
}
Thelist. onmouseover = function (aEvent ){
Var myEvent = window. event? Window. event: aEvent;
Var fm = myEvent. fromElement;
If (IsChild (fm, this) | fm = this) return; // filter the sub-element event
If (this. status = "active") return;
Tempref = this;
ClearTimeout (waitInterval );
WaitInterval = window. setTimeout ("tempref. LoadTab ();", MouseDelayTime );
}
Thelist. onmouseout = function (aEvent ){
Var myEvent = window. event? Window. event: aEvent;
Var em = myEvent. toElement;
If (IsChild (em, this) | em = this) return; // filter the sub-element event
If (this. status = "active") return;
ClearTimeout (waitInterval );
}
If (ulistlinkurl. indexOf ("# default ")! =-1 ){
Thelist. setActive (true );
Ulobj. activetab = thelist;
Ajccache [ulistlinkurl] = getElement (ulistlinktarget). innerHTML;
} Else {
Thelist. setActive (false );
}
}
If (ulobj. activetab = null) ulobj. activetab = ulist [0];
}
}
Function getXmlhttp ()
{
Var http_request;
If (window. XMLHttpRequest ){
Http_request = new XMLHttpRequest ();
If (http_request.overrideMimeType ){
Http_request.overrideMimeType ("text/xml ");
}
}
Else if (window. ActiveXObject ){
Try {
Http_request = new ActiveXObject ("Msxml2.XMLHTTP ");
} Catch (e ){
Try {
Http_request = new ActiveXObject ("Microsoft. XMLHTTP ");
} Catch (e ){}
}
}
If (! Http_request ){
Window. alert ("can't create XMLHttpRequest object .");
Return null;
}
Return http_request;
}
Function loadAJAXTab (url, contentid ){
Var ocontent = getElement (contentid );
If (ajccache [url] = null ){
Var xhttp = getXmlhttp ();
Xhttp. onreadystatechange = function (){
If (xhttp. readyState = 4 & (xhttp. status = 200 | window. location. href. indexOf ("http") =-1 ))
{
Ocontent. innerHTML = xhttp. responseText;
Ajccache [url] = ocontent. innerHTML;
}
}
Xhttp. open ("GET", url, true );
Xhttp. send (null );
} Else {
Ocontent. innerHTML = ajccache [url];
}
}
Window. onerror = function () {return true}
For more information, see