10

How do I have a Javascript confirm() box with "Yes" or "No" instead of the default "Ok" or "Cancel" ?

copenndthagen
  • 49,230
  • 102
  • 290
  • 442
  • 1
    You cant do this out of the box. You'd have to make your own dialog. – TJHeuvel Aug 04 '11 at 07:37
  • see [here](http://stackoverflow.com/questions/18217063/custom-js-confirm-modals-using-jquery-deferred-and-issues-with-return-values-bas/18374548#18374548) – Ulug'bek Aug 22 '13 at 09:14
  • I made my own confirm dialog because i dont like the standard one. https://github.com/stein189/YesNoDialog its really simpel to use and you can adjust it as you wish – Szenis May 16 '15 at 20:05

4 Answers4

15

The javascript confirm dialog cannot be customized.

If you require dialog customization I would suggest looking at JQuery UI - Dialog

Qwerty
  • 29,062
  • 22
  • 108
  • 136
cillierscharl
  • 7,043
  • 3
  • 29
  • 47
4

You cannot do it with standard javascript.

You have this workaround for IE only (source):

<script language=javascript>

/*@cc_on @*/
/*@if (@_win32 && @_jscript_version>=5)

function window.confirm(str)
{
    execScript('n = msgbox("'+str+'","4132")', "vbscript");
    return(n == 6);
}

@end @*/
var r = confirm("Can you do it?");
alert(r);
</script>

Or, you can use custom dialog from jquery ui

JMax
  • 26,109
  • 12
  • 69
  • 88
1

To put it simply i think you can't. There are a lot of answers about that on stack overflow, for example this one : custom choices in javascript confirm dialog that states it. If you want to do it, you have to use your own dialogs like those of jquery ui

Community
  • 1
  • 1
Nicola Peluchetti
  • 76,206
  • 31
  • 145
  • 192
0

Today, you can do it simply with javascript. There's is a simple js library called notiejs that has a confirm option.

With a simple line

notie.confirm('Title text', 'Yes button text', 'No button text', yes_callback)

you can have a custom confirm box. (Maybe the style or the interaction won't fit your use case but I'm just pointing out that it is possible).

Raphael Parent
  • 474
  • 5
  • 9