How to write my own confirmation dialog in javascript?

I want to write something that acts the same as confirm () in javascript, but I want to write it myself so that I can hide the dialog box. I'm having trouble considering how I basically get the javascript thread to wait for the user to respond, and then return true or false.

+3
source share
5 answers

If I were you, I would look at one of the popular javascript libraries. Most of them contain some kind of modal dialogue.

The pair I found for jQuery, jqModal and SimpleModal .

When you create a modal dialog, you need to bind events to buttons so that you do something like:

function askUserYesOrNo() {
  var myDialog = $('<div class="mydialog"><p>Yes or No?</p><input type="button" id="yes" value="Yes"/><input type="button" id="no" value="No"/></div>');
  $("#yes").click(handleYes);
  $("#no").click(handleNo);
  myDialog.modal(); //This would have to be replaced by whatever syntax the modal framework uses
}

function handleYes() {
  //handle yes...
}

function handleNo() {
  //handle no...
}
+5

- -, , .

, jqModal, jQuery, , ; Googling jquery modal yui modal .

+3
+1

. showModalDialog (mozilla), , Internet Explorer. Firefox 3 Safari ( , , 3,1 , iPhone).

0
source

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


All Articles