开发者

Using HTMLDocument to manipulate HTML and show it in WebBrowser-control

开发者 https://www.devze.com 2023-01-11 05:31 出处:网络
I am trying to manipulate a requested document in the WPF WebBrowser-control. I already managed it to invoke JavaScript on loaded document, but I am not able to change the s开发者_如何转开发hown HTML-

I am trying to manipulate a requested document in the WPF WebBrowser-control. I already managed it to invoke JavaScript on loaded document, but I am not able to change the s开发者_如何转开发hown HTML-code in the control itself.

My (very simplified) code in the OnNavigating-Handler looks like this:

mshtml.HTMLDocument doc = (mshtml.HTMLDocument)View.browser.Document;
HTMLTableClass table = doc.getElementById("someTable") as HTMLTableClass;

if (table != null)
{    
    table.appendChild((IHTMLDOMNode)(doc.createElement("<tr>") as IHTMLElement));
}
doc.close();

The -element doesn't get appended to displayed document in the control. Any hints are very appreciated!


I finally got it. Its only possible to change the content of the table by adding rows and cells which i wanted to avoid in first place. My approach was to directly change the content of the -tag, which didnt work.

mshtml.IHTMLTableRow row = table.IHTMLTable_insertRow(-1) as mshtml.IHTMLTableRow;
mshtml.IHTMLElement c = (mshtml.IHTMLElement)row.insertCell(0);
c.innerText = "some";
mshtml.IHTMLElement c1 = (mshtml.IHTMLElement)row.insertCell(1);
c1.innerText = "text";
0

精彩评论

暂无评论...
验证码 换一张
取 消