Let InnerText in Firefox Firefox and IE browser can use the writing _javascript skills

Source: Internet
Author: User
Get text method in IE innertext not supported in Firefox
Firefox changed to Textcontent method/attribute

And the whitespace in the middle of the Firefox Chinese text is replaced by a ruthless replacement.
It's extremely inconvenient to use.
Now it's okay to redefine the InnerText method with JavaScript.
So you can also use the InnerText method in Firefox
And this method solves the problem of the white space character in Firefox

How to use:
Put the following script inside the page
Both IE and Firefox can use Obj.innertext to extract text.
Copy Code code as follows:

<script language= "javascript" >
function Isie () {//ie?
if (Window.navigator.userAgent.toLowerCase (). IndexOf ("MSIE") >=1)
return true;
Else
return false;
}
if (!isie ()) {//firefox innertext define
htmlelement.prototype.__definegetter__ ("innertext",
Funct Ion () {
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].textcontent;
Else if (childs[i].nodetype==3)
AnyString + = Childs[i].nodevalue;
}
Return anystring;
}
);
htmlelement.prototype.__definesetter__ ("innertext",
Function (stext) {
This.textcontent=stext;
}
);
}
</script>

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.