Castell
Castell

Reputation: 19

Close script popup from vb.net

I'm developing a win32 application in vb.net that needs to read info from some websites, using the "WebBrowser" control.

The problem is that sometimes, and randomly, some popups appear while the service is reading a web site, all I need is to close, or "accept" this popup so the service can continue his work.

Hope anyone can help me.

EDIT: I can just disabled the script errors:

WebBrowser1.ScriptErrorsSuppressed = True

This just doesn't show the error, but doesn't solve the problem, still working on it.

Upvotes: 0

Views: 837

Answers (1)

Matt Wilko
Matt Wilko

Reputation: 27322

I don't think that using a webbrowser control is the best way of doing this. If you are reading a web page then you can use the following code to read the html and then parse it yourself (this will avoid any popups)

Public Shared Function GetPageAsString(ByVal address As Uri) As String
    Dim request As HttpWebRequest
    Try
        request = DirectCast(WebRequest.Create(address), HttpWebRequest)
        Using response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
            Using reader As StreamReader = New StreamReader(response.GetResponseStream())
                Return reader.ReadToEnd
            End Using
        End Using
    Catch ex As Exception
        MessageBox.Show(ex.Message)
        Return ""
    End Try
End Function

Usage:

Dim url as string = "http://www.bbc.co.uk"
Dim webContent As String = GetPageAsString(New Uri(url))

Upvotes: 2

Related Questions