22

By default, there are two buttons:"ok" and "cancel" in confirm().
Is there a way to rename them?

5
  • 3
    No. confirm() uses a dialog built-in to the browser. There is no way to change the buttons.
    – gen_Eric
    Apr 5, 2014 at 19:46
  • 4
    Sure, change the language of your browser and OS, and they change, tada!
    – adeneo
    Apr 5, 2014 at 19:48
  • 6
    On the positive side, if you cannot rename them, you shouldn't worry for internationalizing them - that's entirely browser's job. )
    – raina77ow
    Apr 5, 2014 at 19:48
  • 3
    You should worry about the labels and give more descriptive texts instead of the browser's generic labels. Having “Delete file” on a button less likely to mess something up (be misunderstood) than labeling it “Ok”. Apr 5, 2014 at 19:53
  • 2
    Not a drop in replacement, but very cool none-the-less. fabien-d.github.io/alertify.js Apr 6, 2014 at 3:24

4 Answers 4

20

https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-confirm

According to the standard that defines confirm(), there is no way to specify custom button labels.

The browser must display a "positive or negative" prompt (e.g. OK/Cancel) to comply with HTML5.

6

No, there isn't. Confirm only takes one argument and that is the message itself.

http://dev.w3.org/html5/spec-preview/user-prompts.html#dom-confirm

Keep in mind these dialogs are modal and blocking, which means once they are executed you lose control over the program flow. You'd be on a safer route if you implemented your dialogs using a javascript library of your choice or building yours.

3

There is a way IF you use a custom modal to confirm. Something like that:

$(document).ready(function() {
  $('#btn').on('click', function () {
    myApp.confirm('Are you sure?', 'Title', function () {
      $('.btn-no').text("No");
      $('.btn-yes').text("Yes");
  });
});
3
  • 29
    That's not changing confirm, that's not using confirm. Dec 17, 2015 at 23:51
  • 11
    @ChrisMartin I think that I was very clear when I said: 'custom modal to confirm' ;) Dec 17, 2015 at 23:57
  • 1
    @IrfanMomin it doesn't override OK/Cancel buttons. This will use another way with a custom modal to treat this situation. Nov 20, 2019 at 13:49
0

You can't change the buttons of the default confirm popup. A workaround is to recreate the whole popup in JavaScript. One such workaround is http://jqueryui.com/dialog/#modal-confirmation

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.