How to create TRULY modal warnings / confirmations in Javascript?

Sifting through replacements prompt() and confirm() for JavaScript. I need to create a pair of acknowledgment () s and alert () s that have three or more parameters. I would like to use the Lightbox class that I am using already. However, none of the substitutions found can return the result of the operation directly, like confirm () and prompt ():

 success = confirm("Success yes / no?"); if (success == true) ...... 

can a replacement be written so that it behaves the same way, that is, it opens a dialog box, waits for user input, and returns which buttons were pressed? Or is it impossible to do (this is what I suspect now), and you need to get around this by attaching the actions to the yes / no / independent buttons?

Edit: I decided to refuse Josh's answer in the end. This is absolutely useful, but it does not answer the question - is there a way to have really modal dialogs in Javascript? It seems not.

+1
source share
2 answers

Most JavaScript infrastructures that have interface components have a dialog that will provide callbacks. Check out jQuery UI, for example: http://jqueryui.com/demos/dialog/

I used it in several projects to do what you describe.

Edit: I was hoping to suggest a workaround. Unfortunately, JavaScript does not include methods for overriding and adding additional buttons or parameters to the default browser-based Alert (), Confirm (), or Prompt () dialog boxes.

+3
source

Both IE and Firefox 3 have a showModalDialog method that allows you to display the entire web page in different ways. However, for a truly cross-browser solution, you cannot use this.

Many of the popular frameworks provide a mechanism for this by displaying an HTML element and disabling access to the rest of the web page while that element is displayed.

+2
source

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


All Articles