JavaScript extension function code _javascript tips to let Firefox support IE in some ways

Source: Internet
Author: User
Tags javascript extension
This section makes Firefox also support IE's InnerText method
Copy Code code 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 HtmlElement in Mozilla)
Copy Code code as follows:

try {
Create span element So, 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 is added ');
}


Add onclick event to Htmlanchorelement
Copy Code code as follows:

try {
Create a element so this 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.target this.target: ' _self ');
}
else if (this.href)
window.open (This.href, this.target this.target: ' _self ');
};
}
catch (e) {
Alert (' click Method for Htmlanchorelement couldn\ ' t is added ');
}

Tracking the ENTER key event
Copy Code code as follows:

function Capturekeys (evt) {
var keycode = evt.keycode? Evt.keycode:
Evt.charcode? Evt.charCode:evt.which;
if (keycode = =) {
//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;
}
Related Article

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.