Javascript Extension function code that allows Firefox to support some ie Methods

Source: Internet
Author: User
Tags javascript extension

Firefox also supports the innertext method of IE.
CopyCode 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 <Childs. length; 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 Firefox's htmlelement have the click method (add click method to htmlelement in Mozilla) copy Code 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'});
};
}< br> catch (E) {
// alert ('click Method for htmlelement couldn \'t be added');
}

Add an onclick event to htmlanchorelement
copy Code 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. OPE N (this. href, this.tar get? This.tar get: '_ Self');
}< br> else if (this. href)
window. Open (this. href, this.tar get? This.tar get: '_ Self');
};
}< br> catch (E) {
// alert ('click Method for htmlanchorelement couldn \'t be added');
}

trace the Enter key event copy Code 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 ();
}< br> var DQ = getcookie ('default-engine ');
If (DQ = NULL) DQ = "baidu_txt ";
submit_query (DQ);
return false;
}< br> return true;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.