Add Yes and No buttons in jQuery confirmation window

I want the Yes and No buttons in the confirmation window without using the jQuery UI dialog box.

Is there any way to do this?

+4
source share
5 answers

No, you cannot change the standard buttons of the Javascript confirmation window.

I suggest you use the jQuery jQuery dialog box .

+6
source

The jQuery UI Dialog Dialog is a very flexible and powerful tool for this. Here is an example of how to ask a user if he wants to delete something:

<div id="dialog_box" style="display: none;"> Really delete? </div> <button class="delete_btn">Delete</button> <script> $('.delete_btn').click(function(){ $('#dialog_box').dialog({ title: 'Really delete this stuff?', width: 500, height: 200, modal: true, resizable: false, draggable: false, buttons: [{ text: 'Yep, delete it!', click: function(){ //delete it } }, { text: 'Nope, my bad!', click: function() { $(this).dialog('close'); } }] }); }); </script> 

// EDIT:

From your initial question, it was not entirely clear that you did not want to use jQuery Dialog (but why mark the question with jquery / jquery-ui?).

AFAIK, there is no other way to accomplish what you want to do. Also, keep in mind that the native JavaScript dialog box text also takes care of the browser language and other local factors. Thus, it may not always be a good idea to deal with this.

+7
source

Good, yes and no (no pun intended). You can use this:

 if (confirm("Would you like an alert?")) { alert("Here you go!"); } 

The confirm function will return true if the user clicked "OK" or false if "Cancel" was pressed. This is pure JavaScript (DOM level 0), so all browsers support this one .

However, as far as I know, there is no way to customize button shortcuts. Thus, you are stuck with the default settings (" Cancel " and " OK " in most browsers, if they are installed in English).

+6
source

You can do this, but only in IE: Javascript Confirm popup. Yes, there is no button instead of OK and Cancel . AFAIK Other browsers do not support it

 <script language="javascript"> function window.confirm(str) { execScript('n = msgbox("' + str + '","4132")', "vbscript"); return (n == 6); } </script> 

If you don't want jQueryUI, but think about a plugin - try http://www.abeautifulsite.net/blog/2008/12/jquery-alert-dialogs/#demo (also mentioned in the linked answer)

+2
source

You cannot change the text of the confirmation window, but you can create your own.

see an example here: - Show the "Yes" and "No" buttons instead of "OK" and "Cancel in confirmation"?

I think you get an idea of ​​a custom confirmation line.

+1
source

Source: https://habr.com/ru/post/1390807/


All Articles