I am currently working on the addition of Internet Explorer, which is supposed to scan an HTML document for URLs in plain text, and then “link” them.
I have access to DOM websites, and I had the idea to cross all DOM nodes and look for “links” using RegEx to replace this text with HTML code, however, when I change the “InnerText” property, IHTMLElement object, all of it child nodes are lost, which seriously affects the website.
Here is the code:
void _webBrowser2Events_DocumentComplete(object pDisp, ref object URL)
{
if (pDisp == _webBrowser2)
{
HTMLDocument pageContent = _webBrowser2.Document;
IHTMLElement bodyHtmlElmnt = pageContent.body;
fixElement(bodyHtmlElmnt);
}
}
And here is 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 do not have children.
Anyone can help me with this problem, I would be very grateful!
Hi
// Henrik