Hello & Thanks ;
The following code doesn't work , no error msg , just returns nothing .
Pls , what am I doing wrong ?
Below this Sub is the full Code :
Here is the full pgm code :
Thanks for your Help...
The following code doesn't work , no error msg , just returns nothing .
Pls , what am I doing wrong ?
Below this Sub is the full Code :
VB.NET:
Private Sub Target_self_Click(sender As Object, e As EventArgs) Handles Target_self.Click
Dim linkElements As HtmlElementCollection =
WebBrowser1.Document.GetElementsByTagName("A")
' Dim firstLink = linkElements.Cast(Of HtmlElement).FirstOrDefault()
If linkElements.Count > 0 Then
Dim firstLink = linkElements.Cast(Of HtmlElement).FirstOrDefault()
If firstLink.GetAttribute("target") = "_blank" Then
firstLink.SetAttribute("target", "_self")
End If
End If
MsgBox("Target_self_Click = " & "Target_self_Click")
End Sub
Here is the full pgm code :
VB.NET:
Public Class GetElementsByTagName
Private Sub GetElementsByTagName_Load(sender As Object, e As EventArgs) Handles MyBase.Load
WebBrowser1.ScriptErrorsSuppressed = True
WebBrowser1.Navigate("http://vmars.us/SafeBrowser/SafeBrowserHome.html")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Navigate(txbAddress.Text)
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Dim PageElements As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("img")
txbAddress.Text = WebBrowser1.Url.ToString
For Each CurElement As HtmlElement In PageElements
TextBox2.Text = TextBox2.Text & CurElement.GetAttribute("src") & Environment.NewLine
Next
End Sub
Private Sub Target_self_Click(sender As Object, e As EventArgs) Handles Target_self.Click
Dim linkElements As HtmlElementCollection =
WebBrowser1.Document.GetElementsByTagName("A")
' Dim firstLink = linkElements.Cast(Of HtmlElement).FirstOrDefault()
If linkElements.Count > 0 Then
Dim firstLink = linkElements.Cast(Of HtmlElement).FirstOrDefault()
If firstLink.GetAttribute("target") = "_blank" Then
firstLink.SetAttribute("target", "_self")
End If
End If
MsgBox("Target_self_Click = " & "Target_self_Click")
End Sub
Private Sub BackButton_Click(sender As Object, e As EventArgs) Handles BackButton.Click
' WebBrowser1.ScriptErrorsSuppressed = True
WebBrowser1.Navigate("http://vmars.us/SafeBrowser/SafeBrowserHome.html")
End Sub
End Class
Thanks for your Help...