home / experts / javascript / column35 |
|
If you've reached this site, you are probably familiar with the basic protocols, such as http: and ftp:. JavaScript-enabled browsers support the javascript: protocol, which lets you execute statements rather than loading a new document. For example, enter the following URL in your browser:
Now enter a two-statement URL:
As you can see, it is possible to enter multiple statements after the preceding javascript: specification. Also note that a semicolon is not necessary after the last statement in the URL. Entering a javascript: URL in the browser's Location bar is almost useless. However, we can implement javascript: URLs in various browser elements. The most trivial implementation is a simple link:
Simply click the following link, and an alert box will appear: Hello World. If it doesn't work, make sure JavaScript is currently enabled in your browser. Notice the alternation of quotes. Since the The JavaScript statement used in a javascript: URL should not return any value. For example, the When taking advantage of the javascript: protocol, we must make sure the statement doesn't return any value. Therefore, we need to apply the
The When inserting several statements in a single javascript: URL, all value-returning statements require a
Note that the entire javascript: URL should be as compact as possible. Long javascript: URLs tend to generate errors or crash the browser. We suggest that you stick to a maximum of about 500 characters. |
Produced by Yehuda Shiran and Tomer Shiran
Created: February 1, 1999
Revised: February 1, 1999
URL: http://www.webreference.com/js/column35/protocol.html