如何阻止在网络浏览器控制Flash元素 [英] How to block flash elements in the web browser control

查看:164
本文介绍了如何阻止在网络浏览器控制Flash元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立在它与WebBrowser控件C#应用程序,并和我试图找出一个办法让网页中的Flash内容无法显示,因为它占用了的的我的CPU和内存。我一直在试图删除<对象> 在页面中的标签(这里只有一个)经由browser.Document.GetElementsByTagName得到它(对象),并设置其outerHtml为空字符串。它返回一个元素(由Count属性确认),但访问的第一个元素([0])给出一个索引超出范围的错误。我试着通过foreach循环,但没有做它发生在所有的和没有错误。如果我尝试检索< D​​IV> 元素,而不是<对象> 元素,foreach循环运行。我在这里做得不对,有一个bug,还是有更好的方法来去除毛边内容?任何帮助非常AP preciated。

I building a C# application with a WebBrowser control in it and and I am trying to figure out a way to get the flash content within the web page to not display as it is sucking up a ton of my CPU and memory. I've been trying to remove the <object> tag within the page (there's only one) by getting it via browser.Document.GetElementsByTagName("object") and setting its outerHtml to an empty string. It returns one element (confirmed by the Count property) but accessing the first element ([0]) gives an index out of range error. I've tried doing it via a foreach loop but nothing happens at all and there are no errors. If I try to retrieve <div> elements instead of <object> elements, the foreach loop runs. Am I doing something wrong here, is there a bug, or is there a better way to remove the flash content? Any help greatly appreciated.

我的code:

HtmlElementCollection flashElements = webBrowser.Document.GetElementsByTagName("object");
foreach (HtmlElement element in flashElements)
{
  element.OuterHtml = "";
  MessageBox.Show("Deleted");
}

的的DocumentCompleted事件已被解雇后

顺便说一句,这是正在运行的

By the way, this is being run after the DocumentCompleted event has been fired.

编辑:我想通了,虽然被称为DocumentCompleted事件,它被称为注入的JavaScript Flash内容到页面之前。我已经尝试了一些沉睡般的方法,但他们都从处理过停止网页。任何方式等待更多的时间(5秒左右),而网页继续呈现?

I just figured out that while the DocumentCompleted event is being called, it is being called before JavaScript injects the flash content onto the page. I've tried a few "sleeping"-like methods but they all stop the web page from processing too. Any way to wait for more time (5 seconds or so) while the webpage continues to render?

推荐答案

选项1:
你可以使用一个System.Threading.Timer尝试和等待额外的时间为动态的Flash注入。这不应该运行,而你等待撑起web浏览器。

Option 1: You could use a System.Threading.Timer to try and wait extra time for the dynamically injected Flash. That shouldn't hold up the WebBrowser from running while you wait.

选项2:
尝试类似 FiddlerCore (你会添加到您的应用程序), Privoxy的(这会之外运行你的应用程序在本地计算机上),或者一些其它代理实际上阻止有史以来的Flash(.swf文件)内容获取到本地计算机。随着FiddlerCore,你会监视每个Web请求/响应和杀死基于HTTP内容类型的请求/响应,例如。此选项会招致CPU /内存打到进行代理网络,但仍可能低于闪存使用本身。

Option 2: Try something like FiddlerCore (you would add this to your app), privoxy (this would run outside of your app on your local machine) or some other proxy to actually block the Flash (.swf) content from ever getting to your local machine. With FiddlerCore, you would monitor each web request/response and kill the request/response based on the HTTP content type, for instance. This option would incur the CPU/memory hit of proxying the network, but is still likely less than the Flash is using itself.

这篇关于如何阻止在网络浏览器控制Flash元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆