JS

JavaScript Demos:
Simple Alert Box.

jim.cerny@unh.edu  13-JAN-1998


Displays an alert box on loading.


Discussion.

This is about as simple as a JavaScript example can get, just four lines of HTML.

<html> <body bgcolor="white" onLoad = "alert('Hi, World!')"> </body> </html> This illustrates an event handler called "onLoad" that is triggered by the loading of the page. The onLoad (note bicapitalization) is included in the HTML BODY tag and is set to trigger an alert box with a message ("Hi, World!") that is superimposed on the browser window. The most difficult element is proper placement of the quotation marks (plus to figure out a reason for wanting such an alert).

The onLoad action is so limited, there is no need to include a SCRIPT section. If the page is loaded with a JavaScript-incompatible browser, or, if JavaScript is turned off in the browser, then the page displays a notice and no alert occurs. Recall that with Netscape 3.x you turn off/on JavaScript via Options -> Network Preferences -> Languages.