How to handle iframes in a list?

1

I'm trying to group a series of YouTube videos in my personal blog, all the 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 the following error:

  

googleads.g.doubleclick.net/pagead/viewthroughconversion/962985656/?aid=AAA...N5vJSNXPEwA&foc_id=sooa4yRKGN_zEE8iknghZA&label=followon_view&ptype=view:1   GET    link ... 3DN5vJSNXPEwA & foc_id = sooa4yRKGN_zEE8iknghZA & label = followon_view & ptype = view   net :: ERR_BLOCKED_BY_CLIENT

    
asked by anonymous 20.10.2015 / 18:08

0 answers