Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to close a bootstrap modal with the browser back button instead of going back a page?`

I have found this an issue with smartphones and it can relate to desktops. We have 'modded' our bootstrap modal to be responsive, however when displayed on a smartphone it is in full screen, the user assumes the modal is a page and clicks back to 'close' it. We have included the in the top right X but would also like the back button to close the modal. Anyone have any ideas?

Thanks

like image 284
steve0nz Avatar asked Dec 02 '22 19:12

steve0nz


1 Answers

A better way i found thanks to http://www.mylearning.in/2015/06/close-modal-pop-up-on-back-button.html

    $('#myModal').on('show.bs.modal', function(e) {
        window.location.hash = "modal";
    });

    $(window).on('hashchange', function (event) {
        if(window.location.hash != "#modal") {
            $('#myModal').modal('hide');
        }
    });
like image 177
Raymond Ativie Avatar answered Dec 11 '22 02:12

Raymond Ativie