I have a page with 4-5 different modals attached to it. Each with a unique #value (obv). I am trying to find a way to link to these individual modals' from an external source (in this case an HTML email).
For example:
"Click here to view directions" in the email needs to link to -->> www.myurl.com/#directions
the #directions piece should trigger the : function on page load and have the modal automatically open.
Is this possible or am i only dreaming?
You can use the hastag to decide the content to show. For example,
JS
$(document).ready(function () {
var target = document.location.hash.replace("#", "");
if (target.length) {
if(target=="option1"){
showModal("title1","content1");
}
else if(target=="option2"){
showModal("title2","content2");
}
}else{
showModal("no title","no content");
}
function showModal(title,content){
$('#myModal .modal-title').html(title);
$('#myModal .modal-body').html(content);
$('#myModal').modal('show');
}
});
HTML - Bootstrap modal code
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">...</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
<!-- /.modal -->
this will show content for option1
http://jsfiddle.net/fFcS2/show/#option1
this will show content for option2
http://jsfiddle.net/fFcS2/show/#option2
the code
http://jsfiddle.net/fFcS2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With