1

I want:

Detect events in the youtube iframe. Examples are click and touchstart.

My problem:

CODEPEN

I get

Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http://s.codepen.io" from accessing a frame with origin "https://www.youtube.com". The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "https". Protocols must match.

I guess the problem comes from being logged into youtube.

My code:

HTML

<iframe id="someid" width="560" height="315" src="http://www.youtube.com/embed/tbaJS14t6Gw" frameborder="0" allowfullscreen></iframe>

JS

$("#someid").load(function(){
  var iframe = $("iframe").contents();
console.error(iframe.find("body").length + "error happens above");

  $("iframe body").on("click", function(){
  alert("click");
});
  });

Further reading:

Detect click event inside iframe

Community
  • 1
  • 1
Toskan
  • 13,911
  • 14
  • 95
  • 185
  • I think you are going to have trouble trying to communicate X-domain through the iFrame. Your linked question doesn't have this problem. – Zach Lysobey Jun 02 '15 at 20:43

0 Answers0