JavaScript Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 2.11

'javascript:' Pseudo-URL Addresses

This section describes what is a 'javascript:' pseudo-URL address and provides several interesting examples of 'javascript:' URLs.

Many Web browsers also support "javascript:" pseudo-URL addresses in the form of:

javascript:statement;statement;...

When a "javascript:" pseudo-URL is given to a browser, it will start to evaluate those JavaScript statements included in the URL. Here are some examples of "javascript:" pseudo-URL addresses that you can try:

1. The following URL will cause the browser to display a text message in small dialog box.

javascript:alert("Hello World!");

2. The following URL will cause the browser to display a new page with a text message.

javascript:document.write("<html><body>Hello World!</body></html>");

3. The following URL will cause the browser to execute a complex JavaScript code resulting a HTML page with prime numbers. Note that the entire URL address must be written in a single line. So you need to join those lines below, copy and paste it to a browser.

javascript:var i, j, is_prime; document.write('<body><pre>'); 
   for ( i=3; i<=30; i+=2 ) { is_prime = true; for ( j=2; j<=i/2; j++)
   { is_prime = i%j > 0; if (!is_prime) break;} 
   if (is_prime) document.writeln('Found a prime number: ' + i); } 
   document.write('</pre></body>');

Now it's your turn to write more "javascript:" URL examples.

Sections in This Chapter

JavaScript Support in Web Browsers

Including JavaScript Codes with HTML "script" Tags

Including 'script' Tags in String Literials

Escaping 'script' Tags in String Literials

Using HTML Entities to Protect HTML Tags

Including JavaScript Codes as External Files

DOM API - The "document" Object

DOM API - The "window" Object

Event Listeners and Objects

'javascript:' Pseudo-URL Addresses

Dr. Herong Yang, updated in 2008
'javascript:' Pseudo-URL Addresses