This presents a dialog containing the warning message and an OK button.
Note that the text that is presented in the dialog is unformatted text and you cannot use HTML in the dialog box.
The title bar of the dialog box cannot be changed from its default setting that tells you that the dialog was invoked by JavaScript. In some browsers, it may just display the name of the browser. This is intended to stop script programmers from masquerading their dialog boxes as those of operating system diagnostics and login screens.
The alert() dialog box is modal on most platforms. It also blocks the script from continuing except on some versions of Netscape Navigator on Unix platforms. This behavior may become more common as desktop operating systems become more Unix-like and the Netscape Navigator core source code is deployed on newer operating systems. It is possible that this behavior will be exhibited on Mac OS X.
This method is useful for debugging. You can use it much like you would have used a printf() in C language debugging. Using alert() can sometimes be useful as an observable effect of calling a function or event handler. If you don't see the alert box, it's likely the event didn't call your handler.
You may be able to accomplish some rudimentary formatting but realistically due to font differences on platforms the only meaningful formatting is to place newline characters (\n) into the text to introduce a line break and to insert leading spaces for indentation.
This method does not return any meaningful value and if it is used in an assignment, the value undefined will be used.
Be aware that the dialog may be modal but that the script may or may not continue while the alert() dialog is displayed. It depends on the platform. On Windows, the script execution pauses until the OK button is clicked. On UNIX, the alert is displayed by a different process or thread and the script execution continues. If you need truly modal behavior you should consider the confirm() or prompt() dialogs instead.
Prev | Home | Next |
Window object | Up | Window.atob() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |