Under IE and Opear, the DOM object supports the innerText attribute, which can easily remove HTML tags.
However, this attribute is not supported in Firefox. Fortunately, the DOM object under FF supports textContent, which is equivalent to innerText.
Demo example:
Hi,I'm cnlei.Welcome to my homepage:http://www.cnlei.com.
Add the innerText attribute to the DOM object under Firefox:
Appendix DOM Reference:
Firefox DOM Reference: http:/ /www.mozilla.org/docs/dom/domref/dom_shortTOC.html <script> <BR>function getInnerText(obj){ <BR> return document.all?obj.innerText:obj.textContent; <BR>} <BR>var str = getInnerText(document.getElementById("TestObj")); <BR>alert(str); <BR></script>IE DOM reference: <script> <BR>var lBrowser = {}; <BR>lBrowser.agt = navigator.userAgent.toLowerCase(); <BR>lBrowser.isW3C = document.getElementById ? true:false; <BR>lBrowser.isIE = ((lBrowser.agt.indexOf("msie") != -1) && (lBrowser.agt.indexOf("opera") == -1) && (lBrowser.agt.indexOf("omniweb") == -1)); <BR>lBrowser.isNS6 = lBrowser.isW3C && (navigator.appName=="Netscape") ; <BR>lBrowser.isOpera = lBrowser.agt.indexOf("opera") != -1; <BR>lBrowser.isGecko = lBrowser.agt.indexOf("gecko") != -1; <BR>lBrowser.ieTrueBody =function (){ <BR> return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body; <BR>}; <br><br>//为Firefox下的DOM对象增加innerText属性 <BR>if(lBrowser.isNS6){ //firefox innerText define <BR> HTMLElement.prototype.__defineGetter__( "innerText", <BR> function(){ <BR> return this.textContent; <BR> } <BR> ); <BR> HTMLElement.prototype.__defineSetter__( "innerText", <BR> function(sText){ <BR> this.textContent=sText; <BR> } <BR> ); <BR>} <br><br>alert(lBrowser.isNS6); <BR></script>http://msdn2.microsoft.com/en-us/library/ms533050.aspx