The way to add JavaScript code to the client is to place it in the pseudo protocol descriptor javascript: the URL that follows. This particular protocol type declares that the principal of the URL is any JavaScript code, which is run by the JavaScript interpreter. If the JavaScript code in Javascript:url contains more than one statement, you must separate the statements with semicolons. Such URLs are as follows:
Javascript:var now = new Date (); "
When the browser loads such a URL, it executes the JavaScript code contained in the URL and displays the string value of the last JavaScript statement as the contents of the new document. This string value can contain HTML tags and is formatted to display exactly the same as other documents loaded into the browser.
JavaScript URLs can also contain JavaScript statements that perform only actions but do not return values. For example:
Javascript:alert ("Hello world!")
When this URL is loaded, the browser executes only the JavaScript code in it, but it does not change the currently displayed document because it does not have a value to display as a new document.
Usually we want to use Javascript:url to execute some JavaScript code that does not change the currently displayed document. To do this, you must ensure that the last statement in the URL does not return a value. One method is to explicitly specify the return value as underfined with the void operator, using statement void 0 only at the end of the Javascript:url. For example, the following URL opens a new, empty browser window without changing the contents of the current window:
Javascript:window.open ("About:blank"); void 0;
If the URL does not have a void operator, the return value of the window.open () method is converted to a string and displayed, and the current window will be overwritten by the document shown below.