Xtending the innerTEXT cross-browser funcationality

I had this problem… since IE browser already supports innerText property when
I add the innerText as the prototype method as mentioned in my prev. post it creates
problem.
So to get around this issue… v need to check if the browser is IE or not and then
apply the java script EVAL method on the prototype accordingly…otherwise it sux…

Herez the code:

var is_ie = (navigator.userAgent.indexOf(‘MSIE’) >= 0) ? 1 : 0;
var is_ie5 = (navigator.appVersion.indexOf(“MSIE 5.5”)!=-1) ? 1 : 0;
//alert(is_ie5 + “\n” + is_ie);

var prescript = “if(typeof HTMLElement!=’undefined’){“;
prescript += “HTMLElement.prototype.innerText getter = function(){“;
prescript += “var tmp = this.innerHTML.replace(/
/gi,\”\\n\”);”;
prescript += “return tmp.replace(/]+>/g,”);”;
prescript += “}; “;

prescript += “HTMLElement.prototype.innerText setter = function(txtStr){“;
prescript += “var parsedText = document.createTextNode(txtStr); “;
prescript += “this.innerHTML = \”\”; “;
prescript += “this.appendChild( parsedText );”;
prescript += “};”;
prescript += “}”
//alert(prescript);
if( is_ie == 0 && is_ie5 == 0)
{
eval(prescript);
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: