Iframe Is Adding Tags, Need To Remove Them
Im trying to get the contents of an iframe (converted to a simple rich text editor) and then modify those contents using jquery, but I am running into problems because in IE and in
Solution 1:
I don't know why .innerText
didn't work (maybe because you are using Firefox). Anyhow, here is another suggestion:
function strip(html)
{
var tmp = document.createElement("DIV");
tmp.innerHTML = html;
return tmp.textContent||tmp.innerText;
}
This was an accepted answer to this Strip HTML from Text JavaScript question.
Solution 2:
I found an AMAZING website that basically rewrites php code for javascript. I used the strip_tags function from there. Check it out...
function strip_tags (input, allowed) {
allowed = (((allowed || "") + "").toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join(''); // making sure the allowed arg is a string containing only tags in lowercase (<a><b><c>)
var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,
commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
return input.replace(commentsAndPhpTags, '').replace(tags, function ($0, $1) {
return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
});
}
Found it at... phpjs.org
Post a Comment for "Iframe Is Adding Tags, Need To Remove Them"