I have to scan an HTML for remote content (Iframe tags, Img tags ,Script tags etc) and remove the links present in them based on certain blacklist. I am able to remove Iframe ,img , script tags whose src points to a Blacklisted URL.
var mySpan = document.createElement(\"span\");
mySpan.innerHTML = \"\";
var block = p[key];
var re = new RegExp(block);
a = document.getElementsByTagName('iframe');
for(i=0;i<a.length;i++)
{
var str = a.item(i).src;
if(str.match(re))
{
a[i].parentNode.replaceChild(mySpan, a[i]);
// + "a.item(i).src = '';
}
}
Similarly for script and img tags . But there can be many more such tags. Can i have a generic solution to traverse all tags in HTML and find/replace links that are blacklisted I am very new to Javascript so a bit weak in its basics. Can this solution work in my case ? I dont want to use JQuery etc libraries as i am doing this on Android.