Use warnings, hints, and confirmations
You can use warning, confirmation, and prompt message boxes to get user input. These message boxes are the interface methods for window objects. Because the window object is at the top of the object hierarchy, it is not necessary to use the full name of these message boxes (such as "Window.alert ()") in the actual application, but using the full name is a good note to help you remember which object these message boxes belong to.
Warning message box
The alert method has a parameter, which is the text string that you want to display to the user. The string is not in HTML format. The message box provides an OK button for the user to close the message box, and the message box is a modal dialog box, which means that the user must close the message box before proceeding.
window.alert("
Welcome! Please press "OK" to continue.");
Confirmation message box
Use the confirmation message box to ask the user a yes-or-no question, and the user can choose to click the OK button or click the Cancel button. The return value of the Confirm method is true or false. The message box is also a modal dialog box: The user must close the dialog box (click a button) before he or she can take the next action.
var truthBeTold = window.confirm("
Click OK to continue. Click Cancel to stop. ");
if (truthBeTold) {
window.alert("
Welcome to visit our
page! ");
} else window.alert("
Good-bye!");
Hint message box
The prompt message box provides a text field in which the user can enter an answer to respond to your prompts. The message box has an OK button and a Cancel button. If you provide a secondary string parameter, the prompt message box displays the secondary string in the text field as the default response. Otherwise, the default text is "<undefined>".
Similar to the alert () and confirm () methods, theprompt method also displays a modal message box. The user must close the message box before continuing the operation
var theResponse = window.prompt("
Welcome? ","
Please enter your name here.");