2

I want to skin my own confirmation dialog using bootstrap modal without having to hook up events and without resorting to any library, except angular or jquery.

Basically, I want to be able to call something like:

if (myConfirm("text")) {
    // handle yes
} else {
    // handle no
};

myConfirm is supposed to show the modal, wait until either yes or no button was pressed and then return true or false.

What's the best way to do this? I am not concerned at all about any IE issues.

4
  • 2
    There is no good way to do that. Make it event-based.
    – Ry-
    Feb 13, 2014 at 1:04
  • And why no libraries? You can make a very nice modal dialog/confirm box using colorbox.
    – aroth
    Feb 13, 2014 at 1:06
  • This question has a practical purpose but it is actually mostly about wanting to understand js better. I want to understand if there is a way to safely circumvent the event base approach of js. BTW: colorbox is event based.
    – Harald
    Feb 13, 2014 at 1:17
  • use showModalDialog to make a modal html dialog instead of confirm() that still gives you the simple non-event sync interface you crave. It's not perfect from a developer standpoint, but it's a lot better from a user standpoint than confirm.
    – dandavis
    Feb 13, 2014 at 1:22

1 Answer 1

3

Your best bet for a blocking function is the old window.showModalDialog method (which has excellent IE support, btw). But you should not use it.

Make it event-based. Especially when for learning purposes. You won't get the bootstrap modal without events. If you want a nicer abstraction, return a Promise from your function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.