gpt4 book ai didi

c# - 如何在 C# 中更新 WebBrowser 控件内的 DOM 内容?

转载 作者:太空狗 更新时间:2023-10-29 22:27:46 25 4
gpt4 key购买 nike

我有一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com