1
Good morning, I have a problem, I wanted to display a modal at the end of each video, in the first video it worked right, but in the second I’m not getting...
Follows code below...
If anyone can help, I’d really appreciate it!
var vid = document.getElementById("video_ctrl");
function playVid() {
myVideo.play();
}
document.getElementById('video_ctrl').addEventListener('ended',myHandler,false);
function myHandler(e) {
$('#myModal').modal('show');
}
document.getElementById('video_ctrl1').addEventListener('ended',myHandler,false);
function myHandler(e) {
$('#myModal1').modal('show');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div id="div_video">
<video autoplay id="video_ctrl" width="100%">
<source src="img/abertura.ogv" type="video/mp4" />
</video>
</div>
<script>
function setvideo(src) {
document.getElementById('div_video').innerHTML = '<video autoplay id="video_ctrl1" style="width: 100%;"><source src="' + src + '" type="video/mp4"></video>';
}
</script>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" onClick="setvideo('img/video2.mp4');" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="myModal1" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" onClick="setvideo('img/video2.mp4');" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
It didn’t work, Now it didn’t open the modal nor the first video :(
– Yuri Rodrigues
Opa @Yurirodrigues, for some reason it didn’t work out as it should, but I don’t have time to investigate now. I edited the answer, so it sure works.
– KaduAmaral
Thank you so much, it worked out! Saved my day!.
– Yuri Rodrigues