HTML and CSS Reference
In-Depth Information
a popup window, calling a function from a link, submitting a form from a link, and so
on. This chapter focuses on how links are used with images.
As you know, HTML hypertext links are usually created by assigning a Web address
or a file name to the HTML
<a href>
tag, for example:
<a href="http://www.ellieq.com">Go Home</a>
If a JavaScript function is assigned to the
<a href>
tag, when the user clicks the link,
the function will be executed (see Example 12.4).
<a href="JavaScript:greetings()"><big>Click here for salutations</big>
<a href="JavaScript: function_name(arguments);"> Do Something </a>
And you can use an event handler with a link (see Chapter 13):
<a href="newpage.htm"
onClick="newwindow();return false"
>Click Here!</A>
<a href=JavaScript: onClick="return handler(arguments)" >
<A HREF="JavaScript:newwindow()" ><IMG SRC="mypic.jpg" border="0"></A>
Like the form object and image object, the
link
object is a property of the
document
object and gives you access to the hypertext links that have been loaded into a document
(see Figure 12.3). It corresponds to the HTML
<a href>
tag. As each HTML form is a Java-
Script element of the
forms[]
array, and each image is assigned to the
images[]
array, so
each link is assigned to the
links[]
array in the order in which the link appears within
the document.
window
document
links[0]
links[1]
links[...]
Figure 12.3
Document object and links.
The first link would be represented as
document.links[0]
. The properties for the
links
object are shown in Tables 12.3 and 12.4.
3
There are no common methods for the
links
object.
3. These properties are common to both Netscape and Internet Explorer. Internet Explorer, however, sup-
ports many more than are listed here.