Hello!
Right now I'm working on a Internet Explorer add on which is supposed to scan a HTML-document for URL's in plain text, and then "linkify" them.
I have access to the websites DOM, and had an idea to traverse all of the DOM nodes and search for "links" using RegEx, to replace these text with HTML-code, however, when changing the "InnerText" property of the IHTMLElement object, all of it's child nodes are lost, which seriously f*cks up the website.
Here's some code:
//This method is called when IE has finished loading a page
void _webBrowser2Events_DocumentComplete(object pDisp, ref object URL)
{
if (pDisp == _webBrowser2)
{
HTMLDocument pageContent = _webBrowser2.Document;
IHTMLElement bodyHtmlElmnt = pageContent.body;
fixElement(bodyHtmlElmnt);
}
}
And here's the fixElement-method:
void fixElement(IHTMLElement node)
{
if (node.innerText!=null && ((IHTMLElementCollection)node.children).length==0)
{
node.innerText= node.innerText.Replace("testString", "replaceWithThis");
}
foreach (IHTMLElement child in (node.children as mshtml.IHTMLElementCollection))
{
fixElement(child);
}
}
This works, but only for nodes that doesn't have any children.
Can anyone please help me with this problem, I would be very grateful!
Regards
//Henrik