Created
February 28, 2014 17:59
-
-
Save thedamon/9276193 to your computer and use it in GitHub Desktop.
Cause back button to close Bootstrap modal windows
Please help me
And here is my modal it is not working bootstrap 3.2.0
### <a href="" data-toggle="modal" data-target="#exampleModal">Mô Tả MP3</a>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog<?php if(mobile()){echo'-centered';}?> modla-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">ஜ۩۞۩ஜ Description ஜ۩۞۩ஜ</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
description...........
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$('div.modal').on('show.bs.modal', function() {
var modal = this;
var hash = modal.id;
window.location.hash = hash;
window.onhashchange = function() {
if (!location.hash){
$(modal).modal('hide');
}
}
});
$('div.modal').on('hide', function() {
var hash = this.id;
history.pushState('', document.title, window.location.pathname);
});
</script>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It works fine for me too but I had the problem with 2 or more visible modals in same page, when I wanted to close the top modal, all modal get close, so I changed a little bit the $(window).on('popstate', function() function and fully works.
This is my first conttribution, hope this helps.