Monday, April 17, 2006

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);
}

0 Comments:

Post a Comment

<< Home