Using JavaScript Pseudo URLs


<a href="javascript:window.alert('Welcome to JavaScript!'):">click here for a surprise</a> 

Another way to call JavaScript code is to use a pseudo URL. When a URL that begins with javascript: is loaded, the code behind that is executed, as can be seen in the preceding code (file url.html).

There are several ways to use such a URLin the form of an image, a link, or a CSS stylebut usually it's the link you will want to use. Note, however, that such a link obviously works only with a browser that supports JavaScript and has it activated.

Warning

When the code after the javascript: URL prefix returns something, the result is printed to the screen. Usually, this is not desirable. You can use the special JavaScript function void() to avoid this:

javascript:void(code_that_would_return_something()); 






JavaScript Phrasebook(c) Essential Code and Commands
JavaScript Phrasebook
ISBN: 0672328801
EAN: 2147483647
Year: 2006
Pages: 178

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net