Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Customize Confirm with "Yes" or "No" [duplicate]

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

like image 713
copenndthagen Avatar asked Aug 04 '11 07:08

copenndthagen


3 Answers

The javascript confirm dialog cannot be customized.

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

like image 197
cillierscharl Avatar answered Oct 08 '22 06:10

cillierscharl


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

like image 35
JMax Avatar answered Oct 08 '22 06:10

JMax


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

like image 28
Nicola Peluchetti Avatar answered Oct 08 '22 04:10

Nicola Peluchetti