[英]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. 我想知道一种删除Windows窗体Web浏览器上的网站元素的方法。 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.
谢谢你的时间。
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 = "";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.