David Amaral
David Amaral

Reputation: 141

How to remove elements from a windows forms webbrowser control

I'd like to know a way of removing elements of a site on a webbrowser of windows forms. I have this code:

namespace Browser
{
    public partial class Form1 : Form
    {
        public Form1()
        {
           InitializeComponent();
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            webBrowser1.Document.GetElementById("ads").Style = "display:none";
            webBrowser1.Document.GetElementById("navigation").Style = "display:none";
            webBrowser1.Document.GetElementById("donate").Style = "display:none";
            webBrowser1.Document.GetElementById("social_bookmarking_buttons").Style = "display:none";
        }
    }
}

As you may notice, i'm just hiding the elements and I want to remove them. Thanks for your time.

Upvotes: 2

Views: 812

Answers (1)

jhmt
jhmt

Reputation: 1421

This works for me to remove the elements.

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
    webBrowser1.Document.GetElementById("ads").OuterHtml = "";
    webBrowser1.Document.GetElementById("navigation").OuterHtml = "";
    webBrowser1.Document.GetElementById("donate").OuterHtml = "";
    webBrowser1.Document.GetElementById("social_bookmarking_buttons").OuterHtml = "";
}

Upvotes: 3

Related Questions