HTML and CSS Reference
In-Depth Information
6.2.7. The javascript URL
The javascript URL actually is a pseudoprotocol, not usually included in
discussions of URLs. With advanced browsers such as Netscape, Opera,
Firefox, and Internet Explorer, the javascript URL can be associated with
a hyperlink and used to execute JavaScript commands when the user
selects the link. While these URLs will work, we don't recommend us-
ing them. Instead, authors should use the onclick attribute to associate
JavaScript commands with elements in their documents. The javascript URL arguments
Following the javascript pseudoprotocol is one or more semicolon-separ-
ated JavaScript expressions and methods, including references to multi-
expression JavaScript functions that you embed within the <script> tag
in your documents (see Chapter 12 for details). For example:
javascript:window.alert('Hello, world!')
javascript:doFlash('red', 'blue'); window.alert('Do not press me!')
are valid URLs you may include as the value for a link reference (see
section ) . The first example contains a single JavaScript method
that activates an alert dialog with the simple message "Hello, world!", if
the user allows JavaScript to run with their browser.
The second javascript URL example contains two arguments: the first
calls a JavaScript function, doFlash , which presumably you have located
elsewhere in the document within the <script> tag and which perhaps
flashes the background color of the document window between red and
blue. The second expression is the same alert method as in the first ex-
ample, with a slightly different message.
The javascript URL may appear in a hyperlink sans arguments, too. In
that case, the browser may open, if enabled, a special JavaScript editor
wherein the user types in and tests various expressions and methods.
Search WWH ::

Custom Search