|ZYCIIS| 如何让WebBrowser不显示和不下载jpg gif png的文件呢? 谢谢

javamy010 2012-12-08 11:42:11
我要用WebBrowser去浏览网站,
因为速度要求,
要求不要去下载图片资源
那WebBrowser应该如何来实现
谢谢

PS:是不下载图片资源,并不是说在WebBrowser中显示后把图片标签去掉

谢谢
...全文
247 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
javamy010 2012-12-11
  • 打赏
  • 举报
回复
引用 5 楼 findcaiyzh 的回复:
Controlling Download and Execution The WebBrowser Control gives you control over what it downloads, displays, and executes. To gain this control, you need to implement your host's IDispatch so it h……
C++的东西还是看不懂啊。。。
javamy010 2012-12-10
  • 打赏
  • 举报
回复


        private void wbSite_Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            if (this.wbSite.Document != null)
            {
                var doc = this.wbSite.Document;
                if (doc != null)
                {
                    var imgs = doc.GetElementsByTagName("img");
                    //"edit_parent"
                    foreach (HtmlElement img in imgs)
                    {
                            Console.WriteLine(img.InnerHtml);
                            img.SetAttribute("src", "");
                            img.SetAttribute("alt", "去除");
                    }
                    var links = doc.GetElementsByTagName("link");
                    foreach (HtmlElement link in links)
                    {
                        Console.WriteLine(link.InnerHtml);
                        link.SetAttribute("href", "去除");
                    }
                }
               
            }
我用上面的方法的话,还是会在页面加载的时候显示图片和样式 如何才能让WebBorswer不显示图片和CSS样式呢? PS:是在不去改IE设置的前题 谢谢
宝_爸 2012-12-10
  • 打赏
  • 举报
回复
Controlling Download and Execution The WebBrowser Control gives you control over what it downloads, displays, and executes. To gain this control, you need to implement your host's IDispatch so it handles DISPID_AMBIENT_DLCONTROL. When the WebBrowser Control is instantiated, it will call your IDispatch::Invoke with this ID. Set pvarResult to a combination of following flags, using the bitwise OR operator, to indicate your preferences. * DLCTL_DLIMAGES, DLCTL_VIDEOS, and DLCTL_BGSOUNDS: Images, videos, and background sounds will be downloaded from the server and displayed or played if these flags are set. They will not be downloaded and displayed if the flags are not set. 没试过,来自: WebBrowser Customization http://msdn.microsoft.com/en-us/library/aa770041(VS.85).aspx
nonocast 2012-12-10
  • 打赏
  • 举报
回复
一个比较dirty的方法,写NDIS驱动,或者利用Winpcap拦截mime是image/*的HTTP请求
threenewbee 2012-12-09
  • 打赏
  • 举报
回复
http://bbs.csdn.net/topics/200056000 http://msdn.microsoft.com/en-us/library/aa770041(VS.85).aspx 中的 Controlling Download and Execution
javamy010 2012-12-09
  • 打赏
  • 举报
回复


        private void wbSite_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if (this.wbSite.Document != null)
            {
                var doc = this.wbSite.Document;
                if (doc != null)
                {
                    var imgs = doc.GetElementsByTagName("img");
                    //"edit_parent"
                    foreach (HtmlElement img in imgs)
                    {
                         img.SetAttribute("src", "");
                    }

                }
                return;
            }
        }
我用这种方法,只是是网页加载后,再把图片去掉 如果在在加,但还没有加载资源的时候去掉 谢谢

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧