Firefox does not support the innerText solution _ javascript skills

Source: Internet
Author: User
What should I do if firefox does not support innerText during the test? In fact, it is very simple. This article provides you with a solution. If you are interested, you can refer to it and hope to help you with the js Code:

The Code is as follows:


Script
Window. onload = function (){

if(window.navigator.userAgent.toLowerCase().indexOf("msie")==0){ //firefox innerText 
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].textContent;
else if(childS[i].nodeType==3)
anyString += childS[i].nodeValue;
}
return anyString;
}
);
HTMLElement.prototype.__defineSetter__( "innerText",
function(sText){
this.textContent=sText;
}
);
};
Var test = document. getElementById ("test ");

Var innerText_s = test. innerText;

If (innerText_s = undefined ){

Alert (test. textContent); // firefox

} Else {

Alert (test. innerText );

};





}





Script

 




Html code




Test1 test2



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.