On mobile devices, the Bootstrap 3 modal remains when I hit the back button.
Here's my html code:
<a id="link-prof" href="" class="dark-blue" data-toggle="modal" data-target="#leavingModal">Link Here<span class="glyphicon glyphicon-chevron-right"></span></a><
<div id="leavingModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<a class="close-btn" data-dismiss="modal"></a>
<div class="modal-body">
<h4 class="modal-title">You are now leaving this page</h4>
<p>Text here and here</p>
</div>
<div class=" text-center">
<button type="button" class="btn btn-lg btn-link" data-dismiss="modal">Cancel</button>
<button id="link-hcp" type="button" class="btn btn-lg btn-danger" data-dismiss="modal" data-href="http://www.anotherpage.com" data-target="_self">I Agree</button>
</div>
</div>
</div>
I also have this in my JavaScript file (not sure if it has any impact on the problem):
$('button').on(touchClick,function(){
var loc = $(this).attr("data-href");
if(loc!='' && loc!=null) window.location = loc;
});
When I click on a link, the modal appears. I then click the "I Agree" button on the modal, and am taking to a new page. On a desktop, when I hit the back button, the modal is no longer there. I would have to click the link again for the modal to appear (which is desired). However, on a mobile device (I tried an iPad and Android), the modal remains when hittting the back button.
After some research, I came across this code:
$('#leavingModal').on('hidden.bs.modal', '.modal', function () {
$(this).removeData('bs.modal');
});
...but it doesn't even fire. I tried different selectors also with no success.
I'd appreciate some help in determining a solution.
Thanks.
Stephen