When you specify a URL in a web browser, the intent is usually to fetch a document from a remote web server.
The javascript: URL method is used to execute a fragment of JavaScript code when the URL is requested.
You can use the javascript: URL as follows:
To call up the debugger console
To interactively execute statements
As document source
As bookmarks
The view-source: URL can be used in Netscape to call up a source view of a document under script control. Its not very portable and not much use for anything other than debugging.
These are all described in separate topics.
You can call up the JavaScript debugger by setting a document location to "javascript:", "livescript:" or "mocha:".
Looking at the internals of the Netscape browser, this debugging console is itself written in HTML with JavaScript dynamic actions.
Mostly, these special URLs will be useful for debugging - getting details of the disk cache may be useful for example. Pulling up the JavaScript debugger page if you detect an error in your script might also be a cool trick.
With a javascript: URL, you can also type the code directly into the location bar of your Netscape browser to see the results of evaluating it right away.
As of JavaScript version 1.1, you can use the void operator to discard the result of an expression.
This javascript: URL form is vailable in the WebTV set top boxes effective from the Summer 2000 release. However, it cannot be typed in manually by the user as it can be in the desktop computer based web browsers.
This technique does not work with MSIE 3.0.
The JavaScript debugger is not present in MSIE at all, although it may be possible to use the Visual J++ debugging tools if you have them installed.
Almost too late for inclusion was a report that History.back() calls that worked in JScript 5.1 started to fail on upgrade to JScript 5.5 service pack 1. In the end it turned out to be related to calling a javascript: URL within an <A HREF="..."> context. In earlier versions of MSIE, you could omit the single and double quotes around the URL. Version 5.5 is no longer forgiving that omission. This may affect other kinds of URL values and other HTML tag attributes in an MSIE 5.5 browser.
<HTML> <HEAD> <SCRIPT> function test() { alert("Test function called"); } </SCRIPT> </HEAD> <BODY> <DIV onClick="javascript:test();">Click on me</DIV> </BODY> </HTML>
Prev | Home | Next |
JavaScript version | Up | JellyScript |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |