views:

1027

answers:

2

in vb.net 2003 , how to disable images loading in webbrowser control

A: 

How to prevent all images loading in webbrowser control?

+2  A: 

The way I have done this in the past is using Regex to replace image tags with empty quotes. Give the following a try, stick it into your DocumentLoaded event, or such:

origHTML = webBrowser.DocumentText
Dim newHTML as String

Dim regex as String = "<img.*/>"

newHTML = Regex.Replace(origHTML, regex, "", RegexOptions.Multiline)
webBrowser.DocumentText = newHTML

This should solve your problem.

Best Regards,

Kyle

Kyle Rozendo
This blocked most of my images, but let a few through. The original regex fails if the terminating > character is on a different line and it always fails if <img is not in lowercase. Also it uses greedy mode which means it matches on the last > character rather than the first, which means it can replace more than you want.So I tweaked the expression a little to "<img.*?>" and to use the options RegexOptions.SingleLine | RegexOptions.IgnoreCaseThis works better (for me), but of course I can not guarantee that I have not overlooked some other scenario.
sgmoore