I want:
Detect events in the youtube iframe. Examples are click and touchstart.
My problem:
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: