Webbrowser control: how to enumerate links on page?

J. Scott Elblein

Well-known member
Joined
Dec 14, 2006
Messages
166
Location
Chicago
Programming Experience
10+
Hello all

I am wondering how to enumerate all links in the current document and actually SEE what they are as strings.

Thanks in advance!
 
Example:
VB.NET:
Expand Collapse Copy
For Each link As HtmlElement In WebBrowser1.Document.Links
    tmp = "link text is: " & link.InnerText
    tmp &= vbNewLine
    tmp &= "link address is: " & link.GetAttribute("href")
    MsgBox(tmp)
Next
If other html elements than text is linked, for instance image (tag), you can read this with InnerHtml instead of InnerText.
 
Thank you John, that works great. :)

As a side question, I am trying to make this app 100% pure .Net 2.0. If I used vbNewLine in the app, is that considered classic vb? And if so, is there a chance of any issues down the road for portability?

I thought I once read something along the lines of, using classic vb code in .net, although possible, is not recommended because on machines without the runtimes, and on devices it can cause problems (or something like that). As I learn .net, I am trying to completely learn pure .net and save the classic vb for apps I code in classic.
 
vbNewLine is not classic vb, it's a Visual Basic .Net constant.

Not sure what you mean, for .Net framework that is only needed.
 
oh ok. I just wanted to be sure.

I wish I could remember exactly what it was that I read about using classic vb to code in .net not being recommended, but I can't. I can't even remember exactly where in my web travels I read it to look up again. Ah well. :)

Just for future reference on my part, is the ONLY time classic vb gets used in .NET when you happen to be using the microsoft.visualbasic namespace? Or is it accidentally possible to slip some classic in there without it? For example string handling using Mid, instr, Left$, Right$, etc.

I constantly find myself wanting to use those out of habit to string handle and have to keep reminding myself about the new stuff. lol
 
Back
Top