In JavaScript we can display information in windows called dialogs (or dialog boxes) that "pop up" on the screen to grab the user's attention. Dialogs typically diplay important messages to users browing the web page. JavaScript allows you easily to display a dialog box containing a message.
The following program displays Welcome to JavaScript Programming! as three lines in a predefined dialog called an alert dialog.
Alert dialog box displaying multiple lines.
The script user the browser's window object to display an alert dialog. The argument to the window object's alert method is the string to display.
The following program displays Welcome to JavaScript Programming! as three lines in a predefined dialog called an alert dialog.
Alert dialog box displaying multiple lines.
<html>
<head>
<title>Printing Multiple Lines in Dialog Box</title>
<script type = "text/javascript">
<!--
window.alert( "Welcome to \n JavaScript\nProgramming!" );
// -->
</script>
</head>
<body>
<p>Click Refresh to run this script again.</p>
</body>
</html>
<head>
<title>Printing Multiple Lines in Dialog Box</title>
<script type = "text/javascript">
<!--
window.alert( "Welcome to \n JavaScript\nProgramming!" );
// -->
</script>
</head>
<body>
<p>Click Refresh to run this script again.</p>
</body>
</html>
The script user the browser's window object to display an alert dialog. The argument to the window object's alert method is the string to display.