1

I'm currently working on an application that modifies a specific web page to hide irrelevant information and the displays it in a WebBrowser control in the application window. Unfortunately as soon as i set the DocumentText Property of the WebBrowser, it navigates to about:blank and the displays the HTML content. However, because it redirects to about:blank, all relative element in the web page become invalid, creating a very odd looking web page with no stylesheet what so ever.

Is there a way i can modify what the WebBrowser control displays, without having it redirect to about:blank and therefore ruining all relative elements?

4

1 回答 1

0

这应该适用于将 HTML 元素注入您的页面,而无需重置 DOM 的其余部分:

private void button1_Click(object sender, EventArgs e)
{
    HtmlElement myElem = webBrowser1.Document.CreateElement("input");
    dynamic element = myElem.DomElement;

    element.SetAttribute("value", "Hello, World!");
    (webBrowser1.Document.GetElementsByTagName("body")[0]).AppendChild(myElem);
}
于 2013-03-20T21:54:52.573 回答