开发者

How to hide HtmlElement in webbrowser control

开发者 https://www.devze.com 2022-12-23 23:05 出处:网络
I have a webbbrowser control that navigates to a page that contains an image, and i want to hide or delete this image from my webbrowser.

I have a webbbrowser control that navigates to a page that contains an image, and i want to hide or delete this image from my webbrowser.

I've tried to set on DocumentCompleted event the method below with no luck:

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

How to hide an htmlelement from a webbrowser control?

My programing language is C#.

Below is my code:

 private void Form_Load(object sender, EventArgs e)
    {
        webBrowser1.Script开发者_运维技巧ErrorsSuppressed = 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";
    }


Try making an html file that contain the script :

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

After that place in your C# code :

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

MessageBox.Show(Results);


I think i am late.but it may help somebody who need it. You can change the outerhtml of that specific image at run time.Like that

myDoc = this.webBrowser1.Document;

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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号