How to handle iframes on a list?

Asked

Viewed 110 times

1

I’m trying to group a series of Youtube videos on my personal blog, all videos are inside an iframe tag, for example:

<iframe class="YTvideo" allowfullscreen="" frameborder="0" height="344"
        src="https://www.youtube.com/embed/LeAkYuMDVGY?wmode=opaque" width="459"></iframe>

I’m trying to manipulate 4 videos and try to capture how many times each video is played with the following code.

//importando biblioteca YT
var tag = document.createElement('script');

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

function onYouTubeIframesAPIReady(){
  var frame = document.querySelectorAll('iframe[src*="youtube"]');
  var player = [frame.length];
  for(var i=0; i < frame.length; i++){
    //Habilitar a jsapi para poder manusear os controles do player
    frame[i].src += "&enablejsapi=true";

    //incorporando cada iframe para um espaço no array de players
    player[i] = new YT.Player(frame[i]);
    player[i].addEventListener('onStateChange', onPlayerStateChange);
  }
}
var onPlayerStateChange = function(event){
  console.log(event.data);
}

The browser reports me the following error:

googleads.g.Doubleclick.net/pagead/viewthroughconversion/962985656/? aid=AAA... N5vjsnxpewa&foc_id=sooa4yRKGN_zE8iknghZA&label=followon_view&ptype=view:1 GET https://googleads.g.Doubleclick.net/pagead/viewthroughconversion/962985656/...3DN5vJSNXPEwA&foc_id=sooa4yRKGN_zE8iknghZA&label=followon_view&ptype=view net:ERR_BLOCKED_BY_CLIENT

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.