Pass video url into Modal - Jquery [duplicate]

0

I'm passing the url into the embed ( #meuid ) like this:

<script>
   $('#treinamentos').on('show.bs.modal', function (event) {
       var button = $(event.relatedTarget) 
       var nome   = button.data('nome') 
       var video  = button.data('video') 

       $('#nmTreinamento').text(nome);   
       $('#meuid').attr('src', 'https://www.youtube.com/watch?v=VaKvZzKyI1s');
    })
</script>

The modal with embed takes the url but does not display the video:

 <div class="modal fade" id="treinamentos" tabindex="-1" role="dialog" aria-labelledby="alterarLabel" style="z-index: 1100;">
        <div class="modal-dialog" role="document">
          <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" id="exampleModalLabel">Deseja excluir o Treinamento ? </h4>
             </div>

             <div class="modal-body">

              <label for="nmTreinamento" id="nmTreinamento"></label>

             <embed id='meuid' 
             type="application/x-shockwave-flash" fs=1
             allowfullscreen="true" allowscriptaccess="always"
             width="940" height="440" align="center"></embed>               
            </div>                
         </div>
    </div>
</div>

Is there a way to pass the url into embed?

    
asked by anonymous 08.01.2016 / 13:43

2 answers

2

You can use jquery itself. Put the id in the required tags, for example:

<embed id='meuid' src="https://www.youtube.com/v/<?=$video?>?version=3"type="application/x-shockwave-flash" fs=1
                 allowfullscreen="true" allowscriptaccess="always"
                 width="940" height="440" align="center"></embed>

Use the attr function of jquery to change the src property of the above tag.

$minhaurl = 'meu link formatado com o id aqui'
$('#meuid').attr('src', $minhaurl)

Any questions you can ask.

    
08.01.2016 / 15:47
2

Following the documentation available on W3Schools :

  

A built-in flash animation

That is, I believe that <embed> of support for files .swf local.

About Youtube videos

The solution I found was <iframe> .

$('#meuid').attr('src', 'https://www.youtube.com/embed/VaKvZzKyI1s');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><iframewidth="420" height="315" id="meuid">
</iframe>

Obs

Note that there is a change to make:

www.youtube.com/ watch?v= VaKvZzKyI1s < www.youtube.com/ embed/ VaKvZzKyI1s

For this you can do for replace :

function changeToEmbed(src){
    return src.replce('watch?v=', 'embed/');
}
    
08.01.2016 / 16:37