Google

JavaScript Pseudo URLs



Using JavaScript Pseudo URLs / pseudoprotocol


<a href="javascript:window.alert('Welcome to JavaScript!'):">click here </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 .

There are several ways to use such a URL in the form of an image, a link, or a CSS style but 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());



you can use the URL pseudoprotocol, javascript: followed by any valid JavaScript expression or expressions separated by semicolons. The result of the expression is returned as a string to your browser window .


javascript:1+3



No comments: