Reputation: 3033
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.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";
}
Upvotes: 4
Views: 8335
Reputation: 9698
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
Upvotes: 1
Reputation: 15993
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!";
Upvotes: 1
Reputation: 139
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);
Upvotes: 1