I am looking to load a PDF URL into an <object data="">
attribute upon the firing of a BS modal link. With the URL of the PDF coming from the href of that modal link.
Below is the code I have adapted from the below question.
Bootstrap 3 - How to load content in modal body via AJAX?
<a href="https://www.example.com/test.pdf" data-remote="false" data-toggle="modal" data-target="#myModal"">
<!-- The Modal body for the press item -->
<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-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<object data="" type="application/pdf" width="100%" height="100%">
<param name="view" value="Fit"></object>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<script>
jQuery("#myModal").on("show.bs.modal", function(e) {
var link = jQuery(e.relatedTarget);
jQuery(this).find(".modal-body object").attr("data",link);
});
</script>
The above loads "[object Object]" into the data attribute.
An alternative I have tried is:
<script>
jQuery("#myModal").on("show.bs.modal", function(e) {
var link = jQuery(e.relatedTarget.href);
jQuery(this).find(".modal-body object").attr("data",link);
});
</script>
and also:
<script>
jQuery("#myModal").on("show.bs.modal", function(e) {
var link = jQuery(this).attr("href"));
jQuery(this).find(".modal-body object").attr("data",link);
});
</script>