Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

93
Vistas
How to stop video after X button is clicked

Currently, the video does not player.stopVideo(); in the code.

To reproduce: Click 1 svg play button, then click the X and you will see that.

How is that fixed in the code so that the same video stops after clicking the X?

Updated Codes:

Click Run, not update to test JSitor code:

Also, autoplay works inside JSitor: https://jsitor.com/qYKcpdB0tj

Backup copy: https://jsfiddle.net/0q63tr2m/

const videoPlayer = (function makeVideoPlayer() {
  const players = [];

  const tag = document.createElement("script");
  tag.src = "https://www.youtube.com/player_api";
  const firstScriptTag = document.getElementsByTagName("script")[0];
  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

  function onPlayerReady(event) {
    const player = event.target;
    player.setVolume(100);
  }

  function addPlayer(video, settings) {
    const defaults = {
      height: 360,
      host: "https://www.youtube-nocookie.com",
      videoId: video.dataset.id,
      width: 640
    };
    defaults.events = {
      "onReady": onPlayerReady
    };

You can see the video still playing here:

enter image description here

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

What you have to do is as follow:

  1. Add an id to your iframe element like so: id="iframe"
  2. Remove player.stopVideo(); from createStopHandler function
  3. On your createStopHandler function, add following code(if you want your video to stop and not pause, then change the func snippet "func":"pauseVideo" into "func":"stopVideo"):

var frame = document.getElementById("iframe");
frame.contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');

This should do it. Here you can see it working: https://jsfiddle.net/vjbex6t1/8/

about 4 years ago · Juan Pablo Isaza Denunciar

0

 function addClickToHome(goHome) {
    goHome.forEach(function addEventHandler(goHome) {
        goHome.addEventListener("click", homeClickHandler);
       //STOP PLAYER AFTER HOME IS CLICKED 
    });
}

Initialize some variable with player globally and stop it when button is pressed to home

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can try this out,

var videoURL = $('#playerID').prop('src');
videoURL = videoURL.replace("&autoplay=1", "");
$('#playerID').prop('src','');
$('#playerID').prop('src',videoURL);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda