Home All Groups Group Topic Archive Search About

WebBrowser1.Document.Links

Author
31 Jan 2006 9:45 PM
jadeandandrew
I've seen code snippets using this control using the properties
"WebBrowser1.Document.Links" which is perfect for the program I'm
trying to write, but I'm using Visual Basic 6 and it doesn't recognise
it?!

I have inserted the WebBrowser1 control and I can use the document
property, but when I use it to get link information, it returns the
error "Object doesn't support this property or method".

Am I doing something wrong? Do I have to enable something? Is there a
way to check the version of my WebBrowser control? and if it's too low,
how can I update it? Thanks!

Author
1 Feb 2006 2:50 AM
mayayana
It works for me. I just tried the following, with a
page loaded into a WB named WB1.
When I click the button I get a list of links
text in a msgbox:

Private Sub Command1_Click()
  Dim i As Long
  Dim s As String
    For i = 1 To WB1.Document.links.length - 1
       s = s & WB1.Document.links(i).innerHTML & vbCrLf
   Next

MsgBox s
End Sub

  If you haven't already, set a reference to MSHTML.TLB
(in the system folder) to get intellisense for the DOM.

   The links collection exists at least as far back as
IE4. And it exists in IE5. I doubt it's removed in
IE6. Your WB version is your IE version. The WB is just
a wrapper for IE.
--
mayayanaX***@mindXXspring.com
(Remove Xs for return email.)
<jadeandand***@july21.co.uk> wrote in message
Show quoteHide quote
news:1138743959.396172.72500@o13g2000cwo.googlegroups.com...
> I've seen code snippets using this control using the properties
> "WebBrowser1.Document.Links" which is perfect for the program I'm
> trying to write, but I'm using Visual Basic 6 and it doesn't recognise
> it?!
>
> I have inserted the WebBrowser1 control and I can use the document
> property, but when I use it to get link information, it returns the
> error "Object doesn't support this property or method".
>
> Am I doing something wrong? Do I have to enable something? Is there a
> way to check the version of my WebBrowser control? and if it's too low,
> how can I update it? Thanks!
>
Author
1 Feb 2006 6:57 AM
jadeandandrew
Thanks for the reply.


I added MSHTML.TLB as before, added the WebBrowser and a Command Button
to a form and wrote your program and it returns the error "Object
Required", debugging on "For i = 1 To WB1.document.links.length - 1"

My IE version is 6.0.2800.1106.xpsp1.020828-1920

Any help would be much appreciated! Thanks.
Author
1 Feb 2006 1:58 PM
mayayana
I'm not sure what to think. I guess the first thing would
be to recheck and make sure that your WB has
actually been named "WB1" and that there's a page
loaded that has links.

  This page seems to indicate that the links collection
has not been dropped from the DOM:

http://msdn.microsoft.com/workshop/author/dhtml/reference/collections/links.
asp

But it says a very odd thing:

"For a objects to appear in the collection, they must have a name and/or id
property."

   That requirement would make the collection useless
and conflict with the general structure of the DOM. It
also doesn't hold true in my tests. The test code I ran was
on a page where none of the A tags had either name or ID.

    I guess you could test for that by making sure that your
test page loaded has at least one A tag with an ID
attribute. But if it turns out that IE6 does, indeed, require
an ID or name attribute then the links collection will
be useless anyway! In that case you could filter the
"all" collection. It's a sloppy approach but should work.
To test each element in all for links:

  If WB1.document.all(index).tagName = "A" then

Show quoteHide quote
>
> I added MSHTML.TLB as before, added the WebBrowser and a Command Button
> to a form and wrote your program and it returns the error "Object
> Required", debugging on "For i = 1 To WB1.document.links.length - 1"
>
> My IE version is 6.0.2800.1106.xpsp1.020828-1920
>
> Any help would be much appreciated! Thanks.
>
Author
2 Feb 2006 7:00 AM
jadeandandrew
Thanks I have tried that and it works fine, the code I am using is as
follows.

Set colLinks = WB1.document.All.tags("A")
For Each colCurrentLink In colLinks
Debug.Print colCurrentLink
Next colCurrentLink

I'd still be interested in why the original method won't work if anyone
can shed some light on it, I hope there's nothing else that doesn't
work that I need later on!

Thanks for your help.
Author
2 Feb 2006 3:00 PM
mayayana
> Set colLinks = WB1.document.All.tags("A")

   That's interesting. I didn't know you
could "force-filter" a collection like that.
I had assumed you'd have to go through each
"all" item and pick them out one by one.

Show quoteHide quote
> For Each colCurrentLink In colLinks
> Debug.Print colCurrentLink
> Next colCurrentLink
>
> I'd still be interested in why the original method won't work if anyone
> can shed some light on it, I hope there's nothing else that doesn't
> work that I need later on!
>
> Thanks for your help.
>