Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

137
Visualizações
Stopping my embedded Youtube Videos on click

I've been struggling with this for a while now and I've tried a number of solutions but I'm totally stuck on this: I have a number of embedded videos from YouTube on my Site and I have navigation buttons. I want the videos to be paused as soon as any of the buttons are clicked, no matter how many of them are playing at that time. I embedded them the classic way by using the iframe code that YouTube gives you when clicking "embed" and gave them the ".yt" class.

My function currently looks like this:

$(function () {
    
    $('#shadingleft').on('click', function () {
        rotateLeft();
        reset();
        selector = selector - 1;
        if (selector <= -1) {
            selector = 9;
        }
        $('.clicked').toggleClass('clicked');
    })
    
    $('#shadingright').on('click', function () {
        rotateRight();
        reset();
        selector = selector + 1;
        if (selector >= 10) {
            selector = 0;
        }
        $('.clicked').toggleClass('clicked');
    })
    
    $('#shadingtop').on('click', function () {
        rotateUp();
        $('.clicked').toggleClass('clicked');
    })
    
    $('#shadingbottom').on('click', function () {
        rotateDown();
        $('.clicked').toggleClass('clicked');
    })
    
    $('.art').on('click', function () {
        $(this).toggleClass('clicked');
    })
    
});

As you can see I already managed to toggle the highlighted ".art" elements in my gallery using toggleClass. Unfortunately it doesn't seem to work for playing and pausing videos. Whenever one of the four "shading..." elements is clicked I want my ".yt" elements to stop playing the embedded video.

Thanks for helping!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This is a actually a big limitation with iframes. Most browsers won't allow a page's scripts to interact with the content of its iframes for security reasons. So chances are that there is no way at all to do that.

One way you could stop videos would be to reload the youtube iframe entierly, but that would put it back to 00:00 as if it was never played.

Another would be to try and fetch the video stream from youtube on your server and then displaying it in a player of your own on your page. (Which is obviously way more complicated than using an iframe)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda