Reputation: 59
I have multiple videos to show in modal. I do not want to create modals for each button to show video seprate. I want to show all videos in single modal under all buttons.
I have found a function. It was working fine on older version of bootstrap but When I change to bootstrap 3.3.7 it did not show video in modal.
Here is my html.
<a href="https://www.youtube.com/embed/7iPoBjiFdho/" class="btn bootpopup" data-toggle="modal" data-target="#popupModal">Open modal</a>
<div id="popupModal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
<iframe width="100%" height="315" src="" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
</div>
</div>
</div>
</div>
Here is js function.
</script>
<script type='text/javascript'>
$(document).ready(function() {
$('.bootpopup').click(function(){
var frametarget = $(this).attr('href');
var targetmodal = $(this).attr('data-target');
if (targetmodal == undefined) {
targetmodal = '#popupModal';
} else {
targetmodal = '#'+targetmodal;
}
if ($(this).attr('title') != undefined) {
$(targetmodal+ ' .modal-header h3').html($(this).attr('title'));
$(targetmodal+' .modal-header').show();
} else {
$(targetmodal+' .modal-header h3').html('');
$(targetmodal+' .modal-header').hide();
}
$(targetmodal).on('show', function () {
$('iframe').attr("src", frametarget );
});
$(targetmodal).modal({show:true});
return false;
});
});
</script>
Upvotes: 0
Views: 1516
Reputation: 511
Try like this, it should works now:
$(document).ready(function() {
$('.bootpopup').click(function(){
var frametarget = $(this).attr('href');
var targetmodal = $(this).attr('data-target');
if (targetmodal === undefined) {
targetmodal = '#popupModal';
}
if ($(this).attr('title') != undefined) {
$(targetmodal+ ' .modal-header h3').html($(this).attr('title'));
$(targetmodal+' .modal-header').show();
} else {
$(targetmodal+' .modal-header h3').html('');
$(targetmodal+' .modal-header').hide();
}
$('iframe').attr("src", frametarget );
$(targetmodal).modal({show:true});
return false;
});
});
https://jsfiddle.net/7nbj5jjj/
Upvotes: 1