Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

284
Views
bookmarklet: ¿obteniendo la hora actual del reproductor iframe de youtube incrustado?

Soy desarrollador javascript novato. Tengo un bookmarklet que puede obtener la hora actual de un video de YouTube.

 javascript:(function(){ ytplayer = document.getElementById("movie_player"); var secs = ytplayer.getCurrentTime(); alert(`${secs}`); })();

Funciona bien en youtube.com. Sin embargo, cuando aplico la misma lógica a un sitio web basado en iframe ( URL aquí ). De acuerdo con la referencia de la API de YouTube, uso function onYouTubePlayerAPIReady() . pero no pasa nada cuando ejecuto el bookmarklet. Aquí está el código

 javascript:function onYouTubePlayerAPIReady() { var ytplayer = new YT.Player('widget2'); var secs = ytplayer.getCurrentTime(); alert(`${secs}`); }

¿Algún experto en API de YouTube puede detectar el problema?

Aquí está el iframe de la muestra de youtube del sitio web

 <iframe frameborder="0" allowfullscreen="1" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" title="YouTube video player" width="100%" height="100%" src="https://www.youtube.com/embed/eSWwIQzKsbY?autoplay=1&amp;mute=0&amp;controls=1&amp;start=0&amp;origin=https%3A%2F%2Fyou-tldr.com&amp;playsinline=1&amp;showinfo=0&amp;rel=0&amp;iv_load_policy=3&amp;modestbranding=1&amp;enablejsapi=1&amp;widgetid=1" id="widget2" data-gtm-yt-inspected-1_25="true"></iframe>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Sí. Tengo una necesidad similar. No creo que hayas llamado a la función onYouTubeIframeAPIReady() . Este es el código de trabajo.

 function onYouTubeIframeAPIReady() { var player = new YT.Player('widget2', {//The id of the div containing the iframe. Should be changed based on the page you're at and the i they gave their player events: { 'onStateChange': onPlayerStateChange//Event listener, fires onPlayerStateChange function whenever the state of the video changes, paused or played } }); function onPlayerStateChange() { currentTime = player.playerInfo.currentTime;//Current Time saved if (player.playerInfo.playerState === 2) {//If video paused, console.log the time console.log(currentTime); } } } onYouTubeIframeAPIReady();//Initial call to the function
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!