Locate a googleAd and focus programatically in .NET
You will need a textbox named
txt_address.Text and a webbrowser control named nav_1 for this to work.
This functions will locate a google ad , focus on it, and display a messagebox with the address
Private Sub Navigate_1(ByVal address As String)
If String.IsNullOrEmpty(address) Then Return
If address.Equals("about:blank") Then Return
If Not address.StartsWith("http://") And _
Not address.StartsWith("https://") Then
address = "http://" & address
End If
nav_1.Navigate(New Uri(address))
Do While nav_1.ReadyState <> 4
My.Application.DoEvents()
Loop
'Declerations
Dim objGoogleAds As mshtml.HTMLIFrame
Dim objDocgoogle1 As mshtml.HTMLDocument
'Find if there are googleads in this page
objDocgoogle1 = nav_1.Document.DomDocument
For Each objGoogleAds In objDocgoogle1.all.tags("iframe")
If objGoogleAds.src Like "*pagead2.googlesyndication*" Then
objGoogleAds.focus()
MsgBox(objGoogleAds.src)
nav_main.Navigate(New Uri(objGoogleAds.src))
Do While nav_main.ReadyState <> 4
My.Application.DoEvents()
Loop
'display the link that a user clicks when he clicks on a googlead!
MsgBox(nav_main.Document.Links(1).GetAttribute("href"))
' to visit the google ad! -> nav_main.Navigate(New Uri(nav_main.Document.Links(1).GetAttribute("href")))
Do While nav_main.ReadyState <> 4
My.Application.DoEvents()
Loop
End If
Exit For
Next
Return
End Sub
txt_address.Text and a webbrowser control named nav_1 for this to work.
This functions will locate a google ad , focus on it, and display a messagebox with the address
Private Sub Navigate_1(ByVal address As String)
If String.IsNullOrEmpty(address) Then Return
If address.Equals("about:blank") Then Return
If Not address.StartsWith("http://") And _
Not address.StartsWith("https://") Then
address = "http://" & address
End If
nav_1.Navigate(New Uri(address))
Do While nav_1.ReadyState <> 4
My.Application.DoEvents()
Loop
'Declerations
Dim objGoogleAds As mshtml.HTMLIFrame
Dim objDocgoogle1 As mshtml.HTMLDocument
'Find if there are googleads in this page
objDocgoogle1 = nav_1.Document.DomDocument
For Each objGoogleAds In objDocgoogle1.all.tags("iframe")
If objGoogleAds.src Like "*pagead2.googlesyndication*" Then
objGoogleAds.focus()
MsgBox(objGoogleAds.src)
nav_main.Navigate(New Uri(objGoogleAds.src))
Do While nav_main.ReadyState <> 4
My.Application.DoEvents()
Loop
'display the link that a user clicks when he clicks on a googlead!
MsgBox(nav_main.Document.Links(1).GetAttribute("href"))
' to visit the google ad! -> nav_main.Navigate(New Uri(nav_main.Document.Links(1).GetAttribute("href")))
Do While nav_main.ReadyState <> 4
My.Application.DoEvents()
Loop
End If
Exit For
Next
Return
End Sub


0 Comments:
Post a Comment
<< Home