VB 24/7  

Go Back   VB 24/7 > .NET > Visual Basic .NET

Reply
 
Thread Tools Display Modes
  #1  
Old 07-08-2008, 03:16 PM
tekno tekno is offline
Junior Member
 
Join Date: Jun 2008
Posts: 1
Default Event Handler for Webbrowser Control

Hello,

I have a form with webbrowser control, and I need some info on how to handle if the user clicks on a link or a button. I belive that there is a way to create a handler to handle these events, but I am not sure how to follow with that.

Thanks
Reply With Quote
  #2  
Old 07-08-2008, 09:07 PM
Sam Sam is offline
Junior Member
 
Join Date: Jul 2008
Posts: 2
Default

are you using VB 2003 or 2005, with VB2005 version of the webbrowser control you can do the following

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

        Dim olink As HtmlElement
        Dim olinks As HtmlElementCollection = WebBrowser1.Document.Links

        For Each olink In olinks
            olink.AttachEventHandler("onclick", AddressOf LinkClicked)
        Next

    End Sub

now you will need to have the link handler that will actually be called when the user click the link.


    Private Sub LinkClicked(ByVal sender As Object, ByVal e As EventArgs)
        Dim link As HtmlElement = WebBrowser1.Document.ActiveElement
        Dim url As String = link.GetAttribute("href")

        MsgBox("Link Clicked: " & link.InnerText & vbCrLf & _
                    "Destination: " & url)
    End Sub
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Forum Jump


All times are GMT. The time now is 11:42 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.