作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个 Windows .Net Form
,其中包含一个 WebBrowser
控件。
此 WebBrowser
根据其 Url
属性显示网页。
我可以在 WebBrowser
控件中修改显示页面的 DOM 吗?
如果是,怎么办?
最佳答案
对于那些有兴趣的人,这是解决方案:
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# - 如何在 C# 中更新 WebBrowser 控件内的 DOM 内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9873668/
我是一名优秀的程序员,十分优秀!