如何更新在C#中的DOM内容WebBrowser控件内? [英] How to update DOM content inside WebBrowser Control in C#?
本文介绍了如何更新在C#中的DOM内容WebBrowser控件内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个窗口的.Net 表格
包含一个 web浏览器
控制。结果
这 web浏览器
显示基于其网址
属性的网页。结果
我可以修改 web浏览器
控件中显示的页面的DOM?结果
如果是的话,怎么样?
I've a windows .Net Form
which contains a WebBrowser
Control.
This WebBrowser
displays a webpage based on its Url
property.
Can I modify the DOM of the displayed page inside the WebBrowser
control ?
If yes, how to ?
推荐答案
对于那些谁感兴趣的话,这里的解决方案:
For those who are interested, here's the solution:
HtmlElement headElement = webBrowser1.Document.GetElementsByTagName("head")[0];
HtmlElement scriptElement = webBrowser1.Document.CreateElement("script");
IHTMLScriptElement domScriptElement = (IHTMLScriptElement)scriptElement.DomElement;
domScriptElement.text = "function applyChanges(){/*DO WHATEVER YOU WANT HERE*/}";
headElement.AppendChild(scriptElement);
// Call the nextline whenever you want to execute your code
webBrowser1.Document.InvokeScript("applyChanges");
这篇关于如何更新在C#中的DOM内容WebBrowser控件内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文