'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:


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); } 

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

Table of Contents

 About This Book

 Introduction to JavaScript

 ECMAScript Language Specification and JavaScript Dialects

 Data Types, Variables and Expressions

 Flow Control Statements

 Creating, Accessing, and Manipulating Arrays

 Defining and Calling Functions

Web Browser Supporting JavaScript

 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

 DOM API - The "window.open" Method

 Event Listeners and Objects

'javascript:' Pseudo-URL Addresses

 Server-Side and Client-Side Web Scripting

 Introduction to Objects

 Defining Your Own Object Types

 Inheritance of Properties and Methods through the Prototype Object Chain

 'jrunscript' - JavaScript Shell Command from JDK

 Using Functions as "Function" Objects

 Introduction to Built-in Object Types

 W3C's Document Object Model (DOM) Specifications


 PDF Printing Version