🌐
W3Schools
w3schools.com › jsref › met_win_confirm.asp
Window confirm() Method
More examples below. The confirm() method displays a dialog box with a message, an OK button, and a Cancel button.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Window › confirm
Window: confirm() method - Web APIs - MDN Web Docs
window.confirm() instructs the browser to display a dialog with an optional message, and to wait until the user either confirms or cancels the dialog.
People also ask

What is the difference between alert() and confirm() in JavaScript?
`alert()` provides a way for the user to acknowledge any information. It displays a simple dialog box with the message and an "OK" button. `confirm()` is useful when you need the user to make a binary decision. It is used to display a dialog box with a message, along with "OK" and "Cancel" buttons.
🌐
scaler.com
scaler.com › home › topics › javascript window confirm() method with examples
JavaScript Window confirm() Method with Examples - Scaler Topics
Is the confirm() method supported in all web browsers?
Yes, the `confirm()` method is supported in all major web browsers, ensuring consistent behavior across different platforms.
🌐
scaler.com
scaler.com › home › topics › javascript window confirm() method with examples
JavaScript Window confirm() Method with Examples - Scaler Topics
Can I use the confirm() method without attaching it to an event?
Yes, you can use the confirm in JavaScript method without an event, but it's typically employed in response to user actions like button clicks or form submissions for effective interaction.
🌐
scaler.com
scaler.com › home › topics › javascript window confirm() method with examples
JavaScript Window confirm() Method with Examples - Scaler Topics
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-window-confirm-method
Javascript Window confirm() Method - GeeksforGeeks
July 12, 2025 - In this example The window.confirm() method displays a confirmation dialog when a user clicks the link. Returning true allows navigation; false cancels it, preventing the link from opening based on the user's choice.
🌐
Scaler
scaler.com › home › topics › javascript window confirm() method with examples
JavaScript Window confirm() Method with Examples - Scaler Topics
January 2, 2024 - Q. How can I customize the message in the confirmation dialog? A. You can provide a custom message as an argument when calling the Javascript to confirm method, like this: confirm("Custom message goes here").
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › javascript fundamentals
Interaction: alert, prompt, confirm
JavaScript Fundamentals · September 8, 2020 · As we’ll be using the browser as our demo environment, let’s see a couple of functions to interact with the user: alert, prompt and confirm. This one we’ve seen already. It shows a message and waits for the user to press “OK”. For example: alert("Hello"); The mini-window with the message is called a modal window.
🌐
PHPpot
phppot.com › javascript › javascript-confirm
JavaScript Confirm Dialog Box with Yes No Alert - PHPpot
February 24, 2024 - This example contains a JS script to map the HTML button’s click event to show the confirmation dialog box. It minimizes the effort of defining JS functions and calling them with the element to show the JavaScript confirmation.
🌐
Tizag
tizag.com › javascriptT › javascriptconfirm.php
Javascript Tutorial - Confirm
Learn how to create a confirm javascript popup box with Tizag.com's Javascript Confirm lesson.
🌐
Codecademy
codecademy.com › docs › javascript › window › confirm()
JavaScript | window | confirm() | Codecademy
June 17, 2023 - The following example uses the confirm() function to ask the user if they wish to exit the page. It uses an if statement to control how the function performs based on the input. The passed in “exit.html” will redirect the user to that page ...
Find elsewhere
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript bom › javascript confirm
JavaScript confirm
December 17, 2023 - let result = window.confirm(question);Code language: JavaScript (javascript)
🌐
Quackit
quackit.com › javascript › codes › javascript_confirm.cfm
JavaScript Confirm
The JavaScript confirm box gives your users a chance to confirm an action before JavaScript runs it. The 'confirm' box is created using JavaScript's built-in confirm() function.
🌐
BitDegree
bitdegree.org › learn › javascript-confirm
Usage of JavaScript Confirm Method: Confirm Message Explained
September 8, 2017 - The confirm() method returns true when users click OK, and false when they click CANCEL or X. This function displays a message in a dialog box. Nowadays, website owners are always aiming to make their pages user-friendly.
🌐
Github
craftpip.github.io › jquery-confirm
jquery-confirm.js | The multipurpose alert & confirm
<a class="twitter" data-title="Goto ... Javascript · $('a.twitter').confirm({ content: "...", }); $('a.twitter').confirm({ buttons: { hey: function(){ location.href = this.$target.attr('href'); } } });...
🌐
Envato Tuts+
code.tutsplus.com › home › coding fundamentals
Confirm Yes or No With JavaScript | Envato Tuts+ - Code
July 21, 2021 - So that’s how you can use the confirm method in JavaScript to present a yes or no selection dialog box. There are some drawbacks of using the confirm method to get user confirmation. One is that the confirmation dialog will not be part of your app or website's UI. It will not use your branding or color scheme. It also cannot be customized, for example if you want to say Yes or No instead of OK and Cancel.
🌐
Javatpoint
javatpoint.com › javascript-confirm
JavaScript Confirm - javatpoint
JavaScript Confirm with javascript tutorial, introduction, javascript oops, application of javascript, loop, variable, objects, map, typedarray etc.
🌐
W3Schools
w3schools.com › js › tryit.asp
JavaScript Confirm Box
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
Shahed Nasser
blog.shahednasser.com › how-to-use-confirm-dialogs-in-javascript
How to Use Confirm Dialogs in JavaScript - Shahed Nasser
September 27, 2021 - For example, we'll show a button that will trigger the confirm dialog on click: <button id="confirmTrigger">Show Confirm</button> <p id="confirmResult"></p> Inside p we'll show the result based on what the user chooses.
🌐
EDUCBA
educba.com › home › software development › software development tutorials › javascript tutorial › javascript confirm
JavaScript Confirm | How Confirm box work in JavaScript
April 12, 2023 - If we click the Ok button then action will move to the next step, if we click the Cancel button then it will terminate the action there itself. Real-time Example: Let suppose we have an online application form for payment method.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
Top answer
1 of 2
8

alert, confirm, and prompt are all DOM APIs that are implemented by the browser. They do not create DOM elements to represent them, and their functionality cannot be exactly recreated with JavaScript because you cannot force the JavaScript engine to wait for the user to click one of your buttons. You can only come close by requiring a callback that will contain the result of the dialog that you create.

function customConfirm(message, callback) {
    message = message.replace(/"\n"/g, "<br />")
    createElement();
    //The create Element is very complicated to create the text box including message. . .
    function clickOkay() {
        callback(true);
    }
    function clickCancel() {
        callback(false);
    }
}
customConfirm("Hello World!", function (result) {
    console.log(result);
});
2 of 2
6

The confirm()-function is a native function brought to you by every browser. It is not created by using javascript. However if you want to reproduce that behaviour you go a way similar to this:

function myConfirm(text, cb){
    
    // We need this later
    var body = document.getElementsByTagName('body')[0];
     
    // First we create a div which holds the alert and give it a class to style it with css
    var overlay = document.createElement('div');
    overlay.className = 'myConfirm';
  
    // The box holds the content
    var box = document.createElement('div');
  
    var p = document.createElement('p');
    p.appendChild(document.createTextNode(text));
  
    // We append the text to the div
    box.appendChild(p);
    
    // Create yes and no button
    var yesButton = document.createElement('button');
    var noButton = document.createElement('button');
    
    // Add text and events to the buttons    
    yesButton.appendChild(document.createTextNode('Yes'));
    yesButton.addEventListener('click', function(){ cb(true); body.removeChild(overlay); }, false);
    noButton.appendChild(document.createTextNode('No'));
    noButton.addEventListener('click', function(){ cb(false); body.removeChild(overlay); }, false);
    
    // Append the buttons to the box
    box.appendChild(yesButton);
    box.appendChild(noButton);

    // Append the box to the Overlay
    overlay.appendChild(box)
    
    // insert the Overlay with box into the dom    
    body.appendChild(overlay);
    
}

myConfirm('Hello there!', function(value){ console.log(value); });
.myConfirm{
  position:fixed;
  width:100%;
  height:100%;
  background:rgba(0,0,0,0.05);
}

.myConfirm>div{
  width:200px;
  margin:10% auto;
  padding:10px 20px;
  border:1px solid black;
  background:#ccc;
}

.myConfirm div p{
  text-align:center;
}

.myConfirm div button{
  width:40%;
  margin:0 5%;
}

This could be an implementation for a self-made alert-box.
Note that the native alert is a synchronous-function. That means the browser stops the JavasScript-engine until the alert-box is closed. You cant clone that behavior but at least you can give the function a callback which is called, when one of the buttons is clicked. In this case the callback just logs the value to the console.

Hope I could help here!

UPDATE to the updated question
Back in the days when JavaScript was new confirm was a valid way to ask the user for a specific value. confirm, prompt and alert are special functions from these days which behave completely different than normal functions since they break the JavaScript-"flow". When you ask why: Well - maybe it was a nice to have-feature back in these days. Note that in earlier versions alert looked like a system-message (in IE it still does). At least in Firefox you can nowadays interact normally with your browser even if alert is called.
That's why it is merely used for debugging only today (and even here console.log is the better choice).

I am pretty sure that today (in FF) the alert is rendered with browser-intern html and CSS, too.

🌐
TutorialsPoint
tutorialspoint.com › How-to-use-JavaScript-to-show-a-confirm-message
How to use JavaScript to show a confirm message?
November 10, 2022 - In this tutorial, we will learn how to use JavaScript to show a confirm message. We use window.confirm() method of JavaScript to show a confirm message. A confirm message is enclosed in a confirm dialog box which is a modal window. Such a window take