---
title: "firefox兼容innerText"
author: "dragon.dwl"
date: "2010-09-13T10:31:27Z"
tags: []
categories: ["Web前端"]
slug: "firefox-innertext"
draft: false
lastmod: "2010-09-13T10:31:27Z"
id: 761841
url: "https://dragon-dwl.iteye.com/blog/761841"
---

```
function isIE(){
    if(window.navigator.userAgent.toLowerCase().indexOf("msie")>=1) 
        return true;
    else
        return false;
}
if(!isIE()){
    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].textContent;
                else if(childS[i].nodeType==3)
                    anyString += childS[i].nodeValue;
            }
            return anyString; 
        }
    );
    HTMLElement.prototype.__defineSetter__("innerText", 
        function(sText){
            this.textContent=sText;
        }
    );
}
```