There are basically three types of pop-up boxes in javascript :
- Alert –>> it just displays a message with an OK button.
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display an alert box.</p>
<button onclick="myFunction()">Click me</button>
<script>
function myFunction() {
alert("Hello! Welcome to edureka!");
}
</script>
</body>
</html>
2 .Confirm –>> it pops up a confirmation message window with OK and Cancel button.
<!DOCTYPE html>
<html>
<body>
<p>Click the button to display a confirm box.</p>
<button onclick="myFunction()">Click me</button>
<script>
function myFunction() {
confirm("Press a button!");
}
</script>
</body>
</html>
3.Prompt –>> it pops up a dialog box asking user input followed confirmation buttons.
<!DOCTYPE html>
<html>
<body>
<p>Click the button to demonstrate the prompt box.</p>
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
<script>
function myFunction() {
var person = prompt("Please enter your name", "Edureka");
if (person != null) {
document.getElementById("demo").innerHTML =
"Hello " + person + "! How are you today?";
}
}
</script>
</body>
</html>