Link Object


link Object

Description

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>

Events

mouseMove, onMouseOver, onClick

Properties

href, protocol, host, hostname, port, pathname, search, hash, target


Properties


href Property

Description

Returns the compete URL for the link.

Syntax

link.href

PartDescription
link An object expression that evaluates to a link object.

Return Value

Returns a string containing the complete URL for the link.

Applies To

Link

Events

mouseMove, onMouseOver, onClick

Properties

protocol, host, hostname, port, pathname, search, hash, target


protocol Property

Description

Returns the protocol portion of the URL.

Syntax

link.protocol

PartDescription
link An object expression that evaluates to a link object.

Return Value

Returns a string containing the protocol portion of the URL.

Remarks

For http://www.microsoft.com, this would return http:.

Applies To

Link

Events

mouseMove, onMouseOver, onClick

Properties

href, host, hostname, port, pathname, search, hash, target


host Property

Description

Returns both the host and port portion of the URL (hostname:port).

Syntax

link.host

PartDescription
link An object expression that evaluates to a link object.

Return Value

Returns a string containing the host and port portion of the URL.

Remarks

For http://www.microsoft.com, this would return www.microsoft.com:80.

Applies To

Link

Events

mouseMove, onMouseOver, onClick

Properties

href, protocol, hostname, port, pathname, search, hash, target


hostname Property

Description

Returns the host portion of the URL, either a name or an IP address.

Syntax

link.hostname

PartDescription
link An object expression that evaluates to a link object.

Return Value

Returns a string containing the hostname portion of the URL.

Remarks

For http://www.microsoft.com, this would return www.microsoft.com.

Applies To

Link

Events

mouseMove, onMouseOver, onClick

Properties

href, protocol, host, port, pathname, search, hash, target


port Property

Description

Returns the port of the URL.

Syntax

link.port

PartDescription
link An object expression that evaluates to a link object.

Return Value

Returns a string containing the port of the URL.

Remarks

For http://www.microsoft.com, this returns 80 (the default for HTTP).

Applies To

Link

Events

mouseMove, onMouseOver, onClick

Properties

href, protocol, host, hostname, pathname, search, hash, target


pathname Property

Description

Returns the pathname in the URL.

Syntax

link.pathname

PartDescription
link An object expression that evaluates to a link object.

Return Value

Returns a string containing the pathname portion of the URL.

Remarks

For http://www.microsoft.com/intdev, this returns /intdev.

Applies To

Link

Events

mouseMove, onMouseOver, onClick

Properties

href, protocol, host, hostname, port, search, hash, target


search Property

Description

Returns the search portion of the URL, if specified.

Syntax

link.search

PartDescription
link An object expression that evaluates to a link object.

Return Value

Returns a string containing the search portion of the URL.

This returns "user," not "?user," in the current implementation; the leading '?' is omitted.

Remarks

For http://www.microsoft.com/intdev?user, this returns user.

Applies To

Link

Events

mouseMove, onMouseOver, onClick

Properties

href, protocol, host, hostname, port, pathname, hash, target


hash Property

Description

Returns the hash portion of the URL, if specified.

Syntax

link.hash

PartDescription
link An object expression that evaluates to a link object.

Return Value

Returns a string containing the hash portion of the URL.

This returns NULL in the current implementation when no hash is specified..

Remarks

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.

Applies To

Link

Events

mouseMove, onMouseOver, onClick

Properties

href, protocol, host, hostname, port, pathname, search, target


target Property

Description

Returns the target of the link, if specified.

Syntax

link.target

PartDescription
link An object expression that evaluates to a link object.

Return Value

Returns a string containing the target of the link.

Remarks

This is the same as the value of the TARGET attribute of the LINK tag.

Applies To

Link

Events

mouseMove, onMouseOver, onClick

Properties

href, protocol, host, hostname, port, pathname, search, hash


Events

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>


mouseMove Event

Description

Fires an event any time the pointer moves over a link.

Syntax

link.mouseMove shift, button, x, y

ValueDescription
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.

Remarks

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)">

Applies To

Link

Events

onMouseOver, onClick

Properties

href, protocol, host, hostname, port, pathname, search, hash, target


onMouseOver Event

Description

Fires an event any time the pointer moves over a link.

Syntax

link.onMouseOver

ValueDescription
link An object expression that evaluates to a link object.

Remarks

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>

Applies To

Link

Events

mouseMove, onClick

Properties

href, protocol, host, hostname, port, pathname, search, hash, target


onClick Event

Description

Fires an event any time you click on a link.

Syntax

link.onClick

ValueDescription
link An object expression that evaluates to a link object.

Remarks

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>

Applies To

Link

Events

mouseMove, onMouseOver

Properties

href, protocol, host, hostname, port, pathname, search, hash, target

© 1996 Microsoft Corporation