Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sadeghbarati/3bdbd8c1a9829d23e2a32d31158e67f3 to your computer and use it in GitHub Desktop.
Save sadeghbarati/3bdbd8c1a9829d23e2a32d31158e67f3 to your computer and use it in GitHub Desktop.
Cause back button to close Bootstrap modal windows
$('div.modal').on('show', 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);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment