JavaScript pop-up boxes, also known as dialog boxes, are a useful feature for creating interactive and informative user experiences on web pages. There are three types of JavaScript pop-up boxes:
- Alert box: Displays an alert message with a single "OK" button.
- Confirm box: Displays a message with "OK" and "Cancel" buttons.
- Prompt box: Prompts the user to input data and returns the entered value.
Here are some code examples for each of these types of pop-up boxes:
- Alert Box:
javascriptalert("This is an alert message!");
- Confirm Box:
javascriptvar result = confirm("Are you sure you want to delete this item?");
if (result) {
// User clicked "OK"
deleteItem();
} else {
// User clicked "Cancel" or closed the dialog box
}
- Prompt Box:
javascriptvar name = prompt("What is your name?");
if (name != null) {
// User clicked "OK" and entered a value
greetUser(name);
} else {
// User clicked "Cancel" or closed the dialog box
}
In each example, the function is called with a message to display in the pop-up box. The confirm and prompt boxes also have a return value that can be used to determine the user's choice or input.