繁体   English   中英

如何在webbrowser控件中隐藏HtmlElement

[英]How to hide HtmlElement in webbrowser control

我有一个webbbrowser控件导航到包含图像的页面,我想从我的webbrowser隐藏或删除此图像。
我试过在下面的方法中设置DocumentCompleted事件而没有运气:

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

如何从webbrowser控件隐藏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);

您可以使用runtimeStyle

IHTMLElement2 domElement = element.DomElement as IHTMLElement2;
domInspectBox.runtimeStyle.visibility ="hidden"; // if you want to hide it
domInspectBox.runtimeStyle.display = "none"; // if you want to empty its place

我想我迟到了。但它可能会帮助那些需要它的人。 您可以在运行时更改该特定图像的outerhtml。就像那样

myDoc = this.webBrowser1.Document;

myDoc.GetElementById("imgToHide").OuterHtml = "Changed html here!";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM