admin管理员组

文章数量:1429005

I have a bootstrap modal. When it is closed some instructions are executed. But now I want to ask if user really want to close it (with a confirm window) What can i do?

Here is my code at the moment.

$('#modal').on("hide.bs.modal", function (e) {
    //Instructions to execute when the modal is closed
});

I have a bootstrap modal. When it is closed some instructions are executed. But now I want to ask if user really want to close it (with a confirm window) What can i do?

Here is my code at the moment.

$('#modal').on("hide.bs.modal", function (e) {
    //Instructions to execute when the modal is closed
});
Share Improve this question asked Mar 1, 2016 at 5:15 Pablo De LucaPablo De Luca 8233 gold badges16 silver badges31 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

Like this?

$('#modal').on("hide.bs.modal", function (e) {
   if(confirm("Are you sure, you want to close?")) return true;
   else return false;
});

Or, just like this:

$('#modal').on("hide.bs.modal", function (e) {
   if(!confirm("Are you sure, you want to close?")) return false;
});
$('#modal').on("hide.bs.modal", function (e) {
  //Instructions to execute when the modal is closed
 if(!confirm("Are you sure, you want to close?")) return false;
});

本文标签: javascriptAsk if user really want to close bootstrap modalStack Overflow