views:

256

answers:

1

Hi,

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";
    }
A: 

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);

Codeffect