HTML The Definitive Guide (75 page)

Read HTML The Definitive Guide Online

Authors: Chuck Musciano Bill Kennedy

BOOK: HTML The Definitive Guide
5.33Mb size Format: txt, pdf, ePub

When the user clicks some place within the image, the browser passes the coordinates of the mouse pointer along with the URL specified in the tag to the document server. The server uses the mouse pointer coordinates to determine which document to deliver back to the browser.

When ismap is used, the href attribute of the containing tag must contain the URL of a server application or, for some HTTP servers, a related map file that contains the coordinate and linking information. If the URL is simply that of a conventional document, errors may result and the desired document will most likely not be retrieved.

The coordinates of the mouse position are screen pixels counted from the upper-left corner of the image beginning with (0,0). The coordinates are added to the end of the URL, preceded by a question mark.

For example, if a user clicks 43 pixels over and 15 pixels down from the upper-left corner of the image displayed from the following link:

the browser sends the following search parameters to the HTTP server:
cgi-bin
imagemap/toolbar.map?43,15

In the example,
toolbar.map
is a special image map file inside the
cgi-bin/imagemap
directory and containing coordinates and links. A special image map process uses that file to match the passed coordinates (43,15 in the example) and return with the selected hyperlink document.

7.5.1.1 Server-side considerations

With mouse-sensitive ismap-enabled image maps, the browser is required to pass along only the URL and mouse coordinates to the server. Converting these coordinates into a specific document is handled by the document server. The conversion process differs between servers and is not defined by the HTML standard.

You need to consult with your web server administrators and perhaps even read your server's documentation to determine how to create and program an image map. Most servers come with some software utility, typically located in a
cgi-bin/imagemap
directory, to handle image maps. And most of these use a text file containing the image map regions and related hyperlinks that is referenced by your image map URL to process the image map query.

Here's an example image map file that describes the sensitive regions in our example image: # Imagemap file=toolbar.map

default dflt.html

circ 100,30,50 link1.html

rect 180,120,290,500 link2.html

poly 80,80,90,72,160,90 link3.html

Each sensitive region of the image map is described by a geometric shape and defining coordinates in pixels, such as the circle with its center point and radius, the rectangle's upper-left and lower-right edge coordinates, and the loci of a polygon. All coordinates are relative to the upper-left corner of the image (0,0). Each shape has a related URL.

An image map processing application typically tests each shape in the order it appears in the image file and returns the document specified by the corresponding URL to the browser if the user's mouse x,y coordinates fall within the boundaries of that shape. That means it's okay to overlap shapes; just be aware which takes precedence. Also, the entire image need not be covered with sensitive regions: if the passed coordinates don't fall within a specified shape, the default document gets sent back to the browser.

This is just one example for how an image map may be processed and the accessory files required for that process. Please huddle with your webmaster and server manuals to discover how to implement a server-side image map for your HTML documents and system.

7.5.2 Client-side Image Maps

The obvious downside to server-side image maps is that they require a server. That means you need access to the required HTTP server or its
cgi-bin
directory, which isn't always available. And server-side image maps limit portability, since not all image map processing applications are the same.

Server-side image maps also mean delays for the user while browsing, since the browser must get the server's attention to process the image coordinates. That's even if there's no action to take, such as a section of the image that isn't hyperlinked and doesn't lead anywhere.

Client-side image maps suffer from none of these difficulties. Enabled by the usemap attribute for the tag, and defined by special and extension tags, client-side image maps let HTML authors include in their documents a map of coordinates and links that describe the sensitive regions of an image. The browser on the client computer translates the coordinates of the mouse position within the image into an action, such as loading and displaying another document. And special JavaScript-enabled attributes provide a wealth of special effects for client-side image maps.
[JavaScript Event Handlers, 13.3.3]

To create a client-side image map, include the usemap attribute as part of the tag.[
7
] Its value is the URL of a segment in an HTML document that contains the map coordinates and related link URLs. The document in the URL identifies the HTML document containing the map; the fragment identifier in the URL

identifies the map to be used. Most often, the map is in the same document as the image itself, and the URL can be reduced to the fragment identifier: a pound sign (#) followed by the map name.

[7] Alternatively, according to the HTML 4.0 standard but not yet implemented by any browser, you may reference a client-side image map by including the usemap attribute with the and form tags, too.

For example, the following source fragment tells the Netscape or Internet Explorer browser that the
map.gif
image is a client-side image map and that its mouse-sensitive coordinates and related link URLs are found in the map section of the document named
map
:
7.5.3 The Tag

For client-side image maps to work, you must include somewhere in the HTML document a set of coordinates and URLs that define the mouse-sensitive regions of a client-side image map and the hyperlink to take for each region that is clicked by the user. Include those coordinates and links as values of attributes in conventional tags or special tags; the collection of specifications or tags are enclosed within the tag and its end tag . The segment may appear anywhere in the body of any HTML

document.


Function:

Encloses client-side image map (usemap) specifications Attributes:

CLASS ONKEYUP

DIR ONMOUSEDOWN

ID ONMOUSEMOVE

LANG ONMOUSEOUT

NAME ONMOUSEOVER

ONCLICK ONMOUSEUP

ONDBLCLICK STYLE

ONKEYDOWN TITLE

ONKEYPRESS

End tag:

; always present

Contains:

map_content

Used in:

body_content

More specifically, the tag may contain either a sequence of tags or conventional HTML content including tags. You cannot mix and match tags with conventional content. Conventional content within the tag may be displayed by the browser; tags will not. If you are concerned about compatability with older browsers, use only tags containing tags.

If you do place tags within a tag, they must include the shape and coords attributes that define a region within the objects that reference the tag.

7.5.3.1 The name attribute

The value of the name attribute in the tag is the name used by the usemap attribute in an or tag to locate the image map specification. The name must be unique and not used by another in the document, but more than one image map may reference the same
specifications. [The ismap and

usemap attributes, 5.2.6.14]

7.5.3.2 The class, id, style, and title attributes
The style sheet display-related style and class attributes for the tag are only useful when the tag contains conventional HTML content, in which case they apply to the content of the tag.
[Inline Styles: The

style Attribute, 9.1.1]
[Style Classes, 9.2.4]

The id and title attributes, on the other hand, are straightforward. They are standard ways to respectively
label the tag for later reference by a hyperlink or program or entitle the section for later review. [The id attribute,

4.1.1.4]
[The title attribute, 4.1.1.5]

7.5.3.3 The event attributes

The various event attributes allow you to assign Javascript handlers to events that may occur within the confines
of the map. [JavaScript Event Handlers, 13.3.3]

7.5.4 The Tag

The guts of a client-side image map are the tags within the map segment. These tags define each mouse-sensitive region and the action the browser should take if that region is selected by the user in an associated client-side image map.


Function:

Defines coordinates and links for a region on a client-side image map Attributes:

ACCESSKEY ONKEYPRESS

ALT ONKEYUP

CLASS ONMOUSEDOWN

COORDS ONMOUSEMOVE

HREF ONMOUSEOUT

ID ONMOUSEOVER

LANG ONMOUSEUP

Other books

The Reckoning by Jeff Long
Rogue by Rachel Vincent
Governing Passion by Don Gutteridge
The Possibility of Trey by J.A. Hornbuckle
The Caller by Karin Fossum
The Girl in a Coma by John Moss
Martyr by Rory Clements

© 100 Vampire Novels 2015 - 2024    Contact for me [email protected]