By default, there are two buttons:"ok" and "cancel" in confirm().
Is there a way to rename them?
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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With