xxxxxxxxxx
// The confirm function is used to display a dialog with ok and cancel. Usage:
var content = confirm("Hello"); // The "hello" means to show the following text
if (content === true) {
// Do whatever if the user clicked ok.
} else {
// Do whatever if the user clicks cancel.
}
// You can also use window.confirm()
The confirm() function in JavaScript displays a dialog box with a message and two buttons, OK and Cancel. The function returns true if the user clicks OK and false if the user clicks Cancel.
Here is an example of how to use the confirm() function:
xxxxxxxxxx
if (confirm("Are you sure you want to proceed?")) {
// user clicked OK
} else {
// user clicked Cancel
}
In this example, a dialog box with the message "Are you sure you want to proceed?" is displayed. If the user clicks OK, the code in the first if block runs. If the user clicks Cancel, the code in the second if block runs.
xxxxxxxxxx
if (window.confirm("Une nouvelle fenêtre va s'ouvrir.")) {
window.open("fenetre.html", "Nouvelle fenêtre", "");
}
xxxxxxxxxx
if (window.confirm("Do you really want to leave?")) {
window.open("exit.html", "Thanks for Visiting!");
}
xxxxxxxxxx
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>confirm</title>
</head>
<script>
function confirm() {
confirm("Alert")
}
</script>
<body>
<button onclick="confirm()">confirm</button>
</body>
</html>
xxxxxxxxxx
onclick="if (! confirm('Deseja mesmo deletar o arquivo links.html?')) { return false; }"