The Link Object

The Link object references a read-only property array that represents every link in the current HTML page. Links are defined as anchor tags with the HREF attribute set. The following code, which continues on the next page, shows how the links on a page can be referenced:

<SCRIPT LANGUAGE="VBScript">
    Sub Button1_OnClick
        MsgBox Document.Links(1).href
    End Sub
</SCRIPT>
<A HREF="http://www.microsoft.com">Microsoft</A><BR> 
<A HREF="http://www.vb-bootcamp.com">VB-Bootcamp</A>
<FORM>
<INPUT TYPE="BUTTON" NAME="BUTTON1">
</FORM> 

Tables 3-12 and 3-13 describe the properties and events of the Link object.

Table 3-12.Link Object Properties

Property Type Description Usage
Href String Returns the complete URL for the current link(http://www.microsoft.com). MyVar=Links(2).Href
Protocol String Returns the protocol portion of the URL for the current link(http:, ftp:). MyVar= Links(2).Protocol
Host String Returns the Host:Port for the current link. (For http://www.microsoft.com, www.microsoft.com:80 is returned.) MyVar=Links(2).Host
HostName String Returns the host portion of the URL for the current link. (For example, http://www.microsoft.com, www microsoft.com is returned.) MyVar= Links(2).HostName
Port Integer Returns the port for communicating with the current link. (For example, for http://www.microsoft.com, 80 is returned.) MyVar=Links(2).Port
PathName String Returns the pathname portion of the complete URL for the current link. (For example, for http://www.microsoft.com/intdev, intdev isreturned.) MyVar= Links(2).PathName
Search String Returns the search portion of the URL beginning with a ?, representing a query. (For example, for http://www.microsoft.com/intdev?user, ?user is returned.) MyVar= Links(2).Search
Hash String Returns the hash portion of the URL string beginning with a #. (For example, for http://www.microsoft.com/intdev#user, #user is returned.) MyVar=Links(2).Hash
Target String Returns the target of the link, if specified. MyVar=Links(2).Target

Table 3-13.Link Object Events

Event Arguments Description Usage
MouseMove Shift, Button, X, Y Fires whenever the mouse moves over the link. Also passes the following arguments: Shift indicates the status of the Shift key. Button indicates which button was pushed, if any. X indicates the horizontal positionof the pointer in pixels. Y indicates the vertical position of the pointer in pixels. Sub Link1_MouseMove (Shift, Button, X, Y)…End Sub
OnMouseOver None Fires whenever the mouse moves over the link. Sub Link2_OnMouseOver…End Sub
OnClick None Fires whenever the link is clicked. Sub Link3_OnClick …End Sub

© 1996 by Scot Hillier. All rights reserved.