HTML The Definitive Guide (135 page)

Read HTML The Definitive Guide Online

Authors: Chuck Musciano Bill Kennedy

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

To create a JavaScript URL, use javascript as the URL's protocol: In the example, the JavaScript function generate_document() gets executed whenever the hyperlink gets selected by the user. The value returned by the function, presumably a valid HTML

document, is rendered and displayed by the browser.

It may be that the executed statement returns no value. In these cases, the current document is left unchanged. For example, this JavaScript URL: pops up an alert dialog box, and does nothing else. The document containing the hyperlink would still be visible after the dialog box gets displayed and is dismissed by the user.

13.3.5 JavaScript Entities

Character entities in HTML consist of an ampersand (&), an entity name or number, and a closing semicolon. For instance, to insert the ampersand character itself in a document text flow, use the character sequence &. Similarly, JavaScript entities consist of an ampersand, one or more JavaScript statements enclosed in curly braces, and a closing semicolon. For example: &{document.fgColor};

More than one statement must be separated by semicolons within the curly braces. The value of the last (or only) statement is converted to a string and replaces the entity in the document.

Normally, HTML entities can appear anywhere in a document. JavaScript entities are restricted to values of tag attributes. This lets you write "dynamic tags" whose attributes are not known until the document is loaded and the JavaScript executed. For example: will set the text color of the document to the color value returned by the individual's favorite_color() function.

13.3.6 The Tag

The tag is a strange beast. It is processed by the web server, and never seen by the browser.

So what you can do with this tag depends on the server you are using, not the reader's browser.

Netscape's server (not to be confused with the Netscape Navigator browser) uses the tag to let you to place JavaScript statements within an HTML document that get processed by the server. The results of the executed JavaScript then get inserted into the document, replacing the tag. A complete discussion of this so-called "server-side" JavaScript is completely beyond this book; we include this brief reference only to document the tag.


Function:

Define server-side JavaScript

Attributes:

None

End tag:

; never omitted

Contains:

JavaScript

Used in:

head_content

Like the