Textcontent innertext-equivalent attribute _javascript techniques under Firefox

Source: Internet
Author: User
Under IE and opear, DOM objects support the InnerText property, which makes it easy to remove HTML tags.
However, the attribute is not supported in Firefox, but the DOM object under FF supports Textcontent, which is equivalent to innertext.

Demo Example:
<p id= "Testobj" >hi,i ' m <strong>cnlei</strong>. Welcome to my homepage:<a href= "http://www.cnlei.com" >http://www.cnlei.com</a>.</p>
<script type= "Text/javascript" >
function Getinnertext (obj) {
return document.all?obj.innertext:obj.textcontent;
}
var str = getinnertext (document.getElementById ("Testobj"));
alert (str);
</script>

Add innertext properties to the DOM object under Firefox:
<script type= "Text/javascript" >
var lbrowser = {};
Lbrowser.agt = Navigator.userAgent.toLowerCase ();
LBROWSER.ISW3C = document.getElementById? True:false;
Lbrowser.isie = ((LBrowser.agt.indexOf ("MSIE")!=-1) && (LBrowser.agt.indexOf ("opera") = = 1) && ( LBrowser.agt.indexOf ("omniweb") = = 1));
LBROWSER.ISNS6 = lbrowser.isw3c && (navigator.appname== "Netscape");
Lbrowser.isopera = LBrowser.agt.indexOf ("opera")!=-1;
Lbrowser.isgecko = LBrowser.agt.indexOf ("Gecko")!=-1;
Lbrowser.ietruebody =function () {
Return (Document.compatmode && document.compatmode!= "Backcompat")? Document.documentElement:document.body;
};

Adding InnerText properties to the DOM object under Firefox
if (LBROWSER.ISNS6) {//firefox innertext define
htmlelement.prototype.__definegetter__ ("InnerText",
function () {
return this.textcontent;
}
);
htmlelement.prototype.__definesetter__ ("InnerText",
function (stext) {
This.textcontent=stext;
}
);
}

alert (LBROWSER.ISNS6);
</script>

Appendix DOM Reference:
Firefox DOM Reference: http://www.mozilla.org/docs/dom/domref/dom_shortTOC.html
IE DOM Reference:
Http://msdn2.microsoft.com/en-us/library/ms533050.aspx

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.