How to hide HtmlElement in webbrowser control

I have a webbbrowser control that moves to a page containing an image and I want to hide or remove this image from my web browser.
I tried to set the below method on the DocumentCompleted event with no luck:

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

How to hide htmlelement from a web browser control?

My programming language is C #.

Below is my code:

  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"; } 
+4
source share
3 answers

Try creating an html file containing the script:

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

After this place in C # code:

 Results = (string)WebBrowser1.Document.InvokeScript("SetHidden"); MessageBox.Show(Results); 
+1
source

I think I'm late. But it can help someone who needs it. You can change the outerhtml of this particular image at runtime. Like this

 myDoc = this.webBrowser1.Document; myDoc.GetElementById("imgToHide").OuterHtml = "Changed html here!"; 
+1
source

You can use 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 
+1
source

Source: https://habr.com/ru/post/1304765/


All Articles