Add URL hash when on click bootstrap modal anchor

I have an anchor to open a modal:

<a href="#delete-{{ $id }}" class="btn btn-danger btn-xs btn-delete btn-fla details" data-toggle="modal" data-target="#remove_property_modal">
    <i class="fa fa-trash"></i>
</a>

The problem is that the url is not changing from http://example.com into http://example.com/#delete-4 .

Upvotes: 2

Views: 2692

Answers (1)

tmg
tmg

Reputation: 20393

Change url hash on show.bs.modal event of bootstrap modal (docs)

$(document).ready(function () {
     $('.modal').on('show.bs.modal', function (e) {
         if (typeof (e.relatedTarget) != "undefined") {
             window.location.hash = $(e.relatedTarget).attr('href');
         } 
     });
});

Upvotes: 3

Related Questions