Video still executing when closing modal

0

I have a modal bootstrap that opens automatically when the page loads. Within this mode there is only one video. However, when this video is executed and the modal is closed the video is still running. How do I, when closing the modal stop the video (iframe from youtube).

<div class="modal fade" id="testemodal">
      <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">&times;</span></button>
            <h4 class="modal-title">xxx</h4>
          </div>
          <div class="modal-body">
            <iframe width="560" height="315" src="https://www.youtube.com/embed/NHqZKNfAVa0"frameborder="0" allowfullscreen></iframe>
          </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><!-- /.modal-content -->
      </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
    
asked by anonymous 10.07.2015 / 14:44

2 answers

0
function closeModal() {
//código para dar stop no vídeo aqui
//use $('#youriframeid').remove(); para forçar a remoção do html do iFrame
//caso queira alguma alternativa para parar o vídeo
$('#youriframeid').remove();

//código para fechar a modal aqui
$("#testemodal").modal("hide");
}

Now just execute this function when you need to close the modal. I hope I have contributed.

    
10.07.2015 / 15:26
1

This way:

$('#youriframeid').attr('src',$('#youriframeid').attr('src'));

If you do a ".remove ()" and then open the modal again, your video will no longer be there. Depending on your need it also answers, but it does not seem to be the right one, unless you create the modal every time you open it.

    
30.05.2018 / 01:19