Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript - rename confirm() buttons

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

like image 618
nicael Avatar asked Apr 05 '14 19:04

nicael


People also ask

How do I change the window confirm button text?

Change Button Label Using jQuery and CSS We have learned to change the label of the button of the confirm box by creating the custom confirm box. Also, we can use the custom libraries to style the confirm box. Now, we can set the button label in confirm box according to the confirmation message.

Should I use confirm JavaScript?

It is a matter of opinion but I would like to venture mine: the confirm is OK but not great. If you want a professional, clean site, use jQuery or something to generate a nice HTML popup. Second, if you can possibly avoid it, don't do confirm dialogs at all. They're annoying and often disregarded.

How does confirm work in JavaScript?

The confirm() method is used to display a modal dialog with an optional message and two buttons, OK and Cancel. It returns true if the user clicks “OK”, and false otherwise. It prevents the user from accessing other parts of the page until the box is closed. message is the optional string to be displayed in the dialog.

How do you say yes in JavaScript?

You can create a JavaScript confirmation box that offers yes and no options by using the confirm() method. The confirm() method will display a dialog box with a custom message that you can specify as its argument.


2 Answers

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.

like image 27
guioconnor Avatar answered Sep 28 '22 04:09

guioconnor


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.

like image 120
guest Avatar answered Sep 28 '22 05:09

guest