HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
JavaScript has three kind of popup boxes: Alert box, Confirm box, and Prompt box
An alert box is often used if you want to make sure information comes through to the user.
When an alert box pops up, the user will have to click "OK" to proceed.
Syntax
The window.alert()
method can be written without the window
prefix.
alert("I am an alert box!");
A confirm box is often used if you want the user to verify or accept something.
When a confirm box pops up, the user will have to click either "OK" or "Cancel" to proceed.
If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box returns false.
Syntax
The window.confirm()
method can be written without the window prefix.
if (confirm("Press a button!")) {
txt = "You
pressed OK!";
} else {
txt = "You pressed Cancel!";
}
A prompt box is often used if you want the user to input a value before entering a page.
When a prompt box pops up, the user will have to click either "OK" or "Cancel" to proceed after entering an input value.
If the user clicks "OK" the box returns the input value. If the user clicks "Cancel" the box returns null.
Syntax
The window.prompt()
method can be written without the window prefix.
let person = prompt("Please enter your name", "Harry Potter");
let text;
if
(person == null || person == "") {
text = "User cancelled
the prompt.";
} else {
text = "Hello " + person + "!
How are you today?";
}
To display line breaks inside a popup box, use a back-slash followed by the character n.
alert("Hello\nHow are you?");