0

In my mvc application I have used one bootstrap popup, I need to check whether any changes are made in textboxes in this popup before closing this window, and give an option to save this before closing. How can I handle the close event of bootstrap popup window? I have tried

$('#myModal').on('hidden.bs.modal', function () {
    // do something…
})

It will only fire after the close event.

tmg
  • 19,895
  • 5
  • 72
  • 76
Jiju John
  • 821
  • 3
  • 14
  • 35
  • 1
    Look at [Bind a function to Twitter Bootstrap Modal Close](http://stackoverflow.com/questions/8363802/bind-a-function-to-twitter-bootstrap-modal-close) – Himanshu Raval Jun 06 '16 at 13:38
  • attach a mutation observer to the modal form fields and trigger your function in that code block. – Rex Jun 06 '16 at 13:39
  • @HimanshuRaval i have mentioned this in my question that this will fire only after the close event, – Jiju John Jun 06 '16 at 13:48
  • check this question http://stackoverflow.com/questions/22221637/prevent-bootstrap-3-modal-from-closing-when-the-form-has-changes – tmg Jun 06 '16 at 13:58

1 Answers1

1

Use the hide.bs.modal event..

$('#myModal').on('hide.bs.modal', function (e) {
    //do something..
})

Example: http://www.codeply.com/go/wTys5mP4nw

Carol Skelly
  • 351,302
  • 90
  • 710
  • 624