javascript: URL (Request method)

Executes some JavaScript code instead of fetching a document.

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:

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.

Warnings:

Example code:

   <HTML>

   <HEAD>

   <SCRIPT>

   function test()

   {

   alert("Test function called");

   }

   </SCRIPT>

   </HEAD>

   <BODY>

   <DIV onClick="javascript:test();">Click on me</DIV>

   </BODY>

   </HTML>

See also:Adding JavaScript to HTML, Bookmarklets, JavaScript Bookmark URLs, JavaScript debugger console, JavaScript Document Source URL, JavaScript Image Source URL, JavaScript interactive URL, mailbox: URL, mailto: URL, URL, void