Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to get the URL of Link in Internet Explorer ?? 1

Status
Not open for further replies.

miq

Programmer
Apr 24, 2002
315
PK
hi,
working with internet control how can i get the url of the link and perhaps download pages from there.


Bye
miq
 
I`m not sure but i have an idea:First you can get the HTML code of the page and then search the &quot;<a href=&quot; tag (hyperliks tag).The address between this tag is the url.
Tip1-You can search the text by InSrt().see object browser.
Tip2-the link may be a picture.
Tip3-read some about html tags. Behnam2204@yahoo.com
BehnamPro
 
you can get to the hyperlinks collection of the webbrowser document quite easily...

to loop thru the hyperlinks in VB, simply write..

for i = 0 to webbrowser.document.links
debug.print webbrowser.document.links(i).href
next

to download a file to your PC...

Declare Function URLDownloadToFile Lib &quot;urlmon&quot; Alias _
&quot;URLDownloadToFileA&quot; (ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long


Function DownloadFile(URL As String, LocalFilename As String) As Boolean

Dim lngRetVal As Long

lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)

If lngRetVal = 0 Then DownloadFile = True

End Function


hope this helps
 
hi sjravee,
how to get the actual URL of a link which is under mouse pointer (i.e. when a pointer is over a hyperlink ).


I tried your code it should be something like this :

Dim i As Object
For Each i In Wb1.Document.links
Debug.Print i
Next


However, you post was timely as well as informative.
star is what u deserve.


Bye
miq
 
The event - StatusTextChange - will show you what is under the mouse pointer, although it will also show other information as well (so be careful)

Grant
 
Webbrowser is a VB control that you can add it from components dialog box. Behnam2204@yahoo.com
BehnamPro
 
Hi guys,
The webbrowser control is essentially IE without the container it is the part of IE that you view web pages in. It can be added to a VB project by adding the Microsoft Internet Control (shdocvw.dll)

PS. getting the current link under the mouse is not easy
especially not with VB. StatusTextChange sometimes is set by the web designer to show alternative text in the status bar. This would therefore cause a problem if you presumed all it is displaying is urls. Also trying to check if the statustext is a valid url can get intensive especially if the site designer has scrolling messages in the status bar.

There is another way to gain access to the Document object model of a web page in VB and that is by adding a reference to to shdocvw.dll (no need to add the component if you dont wont to display the actual web page). Then write the following ...
(createDocumentFromUrl is only available for IE5 and above)

Dim oMSHTML As New MSHTML.HTMLDocument
Dim oDocument As MSHTML.HTMLDocument
Set oDocument = objMSHTML.createDocumentFromUrl(&quot; vbNullString)
While oDocument.readyState <> &quot;COMPLETE&quot;
DoEvents
Wend
debug.print &quot;MY TITLE IS &quot; & oDocument.title



replace &quot; with whatever link you want
PS. got that loop wrong in the previous post, it should be similar to ...

if oDocument.links.length > 0 then
for i = 0 to oDocument.links.length - 1
debug.print oDocument.links(i).href
next
end if
 
correction to previous post:

Set oDocument = objMSHTML.createDocumentFromUrl(...

should say

Set oDocument = oMSHTML.createDocumentFromUrl(...
 
hi,
yes, i am working with shdocvw.dll rather then simple web browser. And i am facing problem with StatusTextChange. This was the reason for this post.
sjravee your code for viewing all links is perfect but how to check individual links with mouse.

Is their a way to get other details from Links Collection like link's text (text which user sees) and also
information with mouse hover operation (perhaps with StausTextChange. if this is possible then comparsion can be done to get the actual URL from the link.


 
Unfortunately statustextchange does not let you know which element caused the text to change


for other link properties:

for i = 0 to oDocument.links.length - 1
debug.print oDocument.links(i).href
debug.print oDocument.links(i).target
debug.print oDocument.links(i).innerText
debug.print oDocument.links(i).innerHTML
next

innerText is the text you see inside a link, however sometimes there are images and other HTML elements that are linked, so innerHTML will let you know the HTML that is enclosed in the a tag. Image map hrefs also will appear in the links collection.


to recieve events such as onmouseover etc you need to
first create a docobject that will respond to events...

private withevents objHTMLDoc as HTMLDocument

you will then be able to trap the event and interogate the element that fired the event

You will find a good example, near the bottom of the page, at:


what you want to do is not easy, especially with frame based pages
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top