gpt4 book ai didi

c# - 如何在 webbrowser 控件中隐藏 HtmlElement

转载 作者:行者123 更新时间:2023-11-30 12:18:16 25 4
gpt4 key购买 nike

我有一个 webbbrowser 控件,可以导航到包含图像的页面,我想从我的网络浏览器中隐藏或删除这张图片。
我尝试在 DocumentCompleted 事件上设置以下方法,但没有成功:

webBrowser1.Document.GetElementById("imgToHide").Style = "display:none";

如何从浏览器控件中隐藏 htmlelement?

我的编程语言是 C#。

下面是我的代码:

 private void Form_Load(object sender, EventArgs e)
{
webBrowser1.ScriptErrorsSuppressed = true;
webBrowser1.Navigate(oURL);
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
//imgCancel is the name of t he image to hide
webBrowser1.Document.GetElementById("imgCancel").Style = "display:none";
}

最佳答案

尝试制作一个包含脚本的 html 文件:

function SetHidden()
{
window.document.all["hiddenText"].style.display="block";
return "ok";
}

在您的 C# 代码中的那个位置之后:

Results = (string)WebBrowser1.Document.InvokeScript("SetHidden");

MessageBox.Show(Results);

关于c# - 如何在 webbrowser 控件中隐藏 HtmlElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2492544/

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