Fun with JavaScript
JavaScript is the language of choice for creating interactive web pages. This is because JavaScript is designed as an extension to HTML and is included within HTML codes.
- OnLoad is a called an event handler. OnLoad tells the browser that the event must happen when the web page is first or initially loaded (that is, produce this Alert window onLoading the web page).
- When the browser sees window.alert(), it knows what to do. Window is called an object and alert() is called a method of the window object. An object can have many methods and for the window object, alert() is one them. Note that () is simply an opening and closing bracket (in case it is hard to read).
- The message is called an argument and arguments must always be enclosed within parentheses (that is, within brackets). The argument belongs to the method alert() and note that it is enclosed with single quotation marks. Note that the whole statement for the onLoad event handler is enclosed with double quotation marks. When two sets of quotation marks are required, then one set must be double and the other set must be single quotation marks. Otherwise the browser will be unable to keep things straight. Omitting these quotation marks will result in an error message. Note that these quotation marks did not appear in the pop-up window.
- If you want the message to be displayed only when the visitor leaves your web page, use onUnload instead of onLoad. You can also change the message to suit your own needs.
- I would suggest that you take some time to "play" with this statement by SWITCHING to NOTEPAD or to a similar text editor, type in a HEAD, TITLE and then the BODY tag as in:
