An object that resides below the document in the scripting object model. This object specifies an array of links for a given document.
The link object is referenced as a read-only property array. A link object is constructed for every link that appears in the HTML document. A link is defined in scripting as the anchor tag <A> containing the HREF attribute <A HREF="http://www.microsoft.com">. All properties of the link object are read-only and are the same as the location object's properties. It is only accessible through the indexed array. The following lines of script would set linktext to the third link on the page (if it exists):
<script language="VBScript"> [some preceding VBScript code] linktext = document.links(2).href [some following VBScript code] </script>
href, protocol, host, hostname, port, pathname, search, hash, target
Returns the compete URL for the link.
link.href
Part Description link An object expression that evaluates to a link object.
Returns a string containing the complete URL for the link.
protocol, host, hostname, port, pathname, search, hash, target
Returns the protocol portion of the URL.
link.protocol
Part Description link An object expression that evaluates to a link object.
Returns a string containing the protocol portion of the URL.
For http://www.microsoft.com, this would return http:.
Returns both the host and port portion of the URL (hostname:port).
link.host
Part Description link An object expression that evaluates to a link object.
Returns a string containing the host and port portion of the URL.
For http://www.microsoft.com, this would return www.microsoft.com:80.
href, protocol, hostname, port, pathname, search, hash, target
Returns the host portion of the URL, either a name or an IP address.
link.hostname
Part Description link An object expression that evaluates to a link object.
Returns a string containing the hostname portion of the URL.
For http://www.microsoft.com, this would return www.microsoft.com.
Returns the port of the URL.
link.port
Part Description link An object expression that evaluates to a link object.
Returns a string containing the port of the URL.
For http://www.microsoft.com, this returns 80 (the default for HTTP).
href, protocol, host, hostname, pathname, search, hash, target
Returns the pathname in the URL.
link.pathname
Part Description link An object expression that evaluates to a link object.
Returns a string containing the pathname portion of the URL.
For http://www.microsoft.com/intdev, this returns /intdev.
Returns the search portion of the URL, if specified.
link.search
Part Description link An object expression that evaluates to a link object.
Returns a string containing the search portion of the URL.
This returns "user," not "?user," in the current implementation; the leading '?' is omitted.
For http://www.microsoft.com/intdev?user, this returns user.
href, protocol, host, hostname, port, pathname, hash, target
Returns the hash portion of the URL, if specified.
link.hash
Part Description link An object expression that evaluates to a link object.
Returns a string containing the hash portion of the URL.
This returns NULL in the current implementation when no hash is specified..
This is the section of the URL after # including the #. For http://www.microsoft.com/intdev#user, this returns #user. If no hash is specified, this property returns NULL.
href, protocol, host, hostname, port, pathname, search, target
Returns the target of the link, if specified.
link.target
Part Description link An object expression that evaluates to a link object.
Returns a string containing the target of the link.
This is the same as the value of the TARGET attribute of the LINK tag.
href, protocol, host, hostname, port, pathname, search, hash
Link events can be used to set status bar text or other custom actions on mouse movement. The following example is an excerpt from an HTML document that uses a text control to display rich information about the links in an image map. The code decides on the link location.
<script language="VBScript" for="Link1" event="mouseMove(shift, button, x, y)"> if (InRect(x, y, 5, 30, 120, 85)=true) then DescribeLink "A full description of Microsoft's product line" [some following VBScript code] </script>
Fires an event any time the pointer moves over a link.
link.mouseMove shift, button, x, y
Value Description link An object expression that evaluates to a link object. shift The status of the shift key. button Indicates which button is pressed, if any. x The horizontal position of the pointer, in pixels. y The vertical position of the pointer, in pixels.
Shift and button are currently set to zero. x and y contain the actual positional data. To attach scripts or behavior to this event, use the SCRIPT tag as follows:
<script language=script-engine for=link-name event="mouseMove(shift, button, x, y)">
href, protocol, host, hostname, port, pathname, search, hash, target
Fires an event any time the pointer moves over a link.
link.onMouseOver
Value Description link An object expression that evaluates to a link object.
Not implemented in current builds.
To attach scripts or behavior to this event, use the SCRIPT tag as follows:
<script language=script-engine for=link-name event="onMouseOver">or attach a script directly in the HTML:
<A HREF="http://www.microsoft.com" onMouseOver="alert ('Clicked here')">To Microsoft</A>
href, protocol, host, hostname, port, pathname, search, hash, target
Fires an event any time you click on a link.
link.onClick
Value Description link An object expression that evaluates to a link object.
Not implemented in current builds.
To attach scripts or behavior to this event, use the SCRIPT tag as follows:
<script language=script-engine for=link-name event="onClick">or attach a script directly in the HTML:
<A HREF="http://www.microsoft.com" onClick="alert ('Clicked here')">To Microsoft</A>
href, protocol, host, hostname, port, pathname, search, hash, target