Some code can only be implemented in IE, and some extension functions must be used if implemented in firefox.
FireFox also supports the innerText method of IE.
The Code is as follows:
Function isIE (){
If (window. navigator. userAgent. toLowerCase (). indexOf ("msie")> = 1)
Return true;
Else
Return false;
}
If (! IsIE () {// firefox innerText define
HTMLElement. prototype. _ defineGetter _ ("innerText ",
Function (){
Var anyString = "";
Var childS = this. childNodes;
For (var I = 0; I If (childS [I]. nodeType = 1)
AnyString + = childS [I]. tagName = "BR "? '\ N': childS [I]. innerText;
Else if (childS [I]. nodeType = 3)
AnyString + = childS [I]. nodeValue;
}
Return anyString;
}
);
HTMLElement. prototype. _ defineSetter _ ("innerText ",
Function (sText ){
This. textContent = sText;
}
);
}
This section makes the HTML element of FireFox have the click method.(Add click method to HTMLElement in Mozilla)
The Code is as follows:
Try {
// Create span element so that HTMLElement is accessible
Document. createElement ('span ');
HTMLElement. prototype. click = function (){
If (typeof this. onclick = 'function ')
This. onclick ({type: 'click '});
};
}
Catch (e ){
// Alert ('click method for HTMLElement couldn \'t be added ');
}
Add an onclick event to HTMLAnchorElement
The Code is as follows:
Try {
// Create a element so that HTMLAnchorElement is accessible
Document. createElement ('A ');
HTMLElement. prototype. click = function (){
If (typeof this. onclick = 'function '){
If (this. onclick ({type: 'click'}) & this. href)
Window. open (this. href, this.tar get? This.tar get: '_ self ');
}
Else if (this. href)
Window. open (this. href, this.tar get? This.tar get: '_ self ');
};
}
Catch (e ){
// Alert ('click method for HTMLAnchorElement couldn \'t be added ');
}
Tracking the Enter key event
The Code is as follows:
Function captureKeys (evt ){
Var keyCode = evt. keyCode? Evt. keyCode:
Evt. charCode? Evt. charCode: evt. which;
If (keyCode = 13 ){
// Cancel key:
If (evt. preventDefault ){
Evt. preventDefault ();
}
Var dq = getCookie ('default-engine ');
If (dq = null) dq = "baidu_txt ";
Submit_query (dq );
Return false;
}
Return true;
}