javascript - Detecting events in embedded youtube iframe? -


i want:

detect events in youtube iframe. examples click , touchstart.

my problem:

codepen

i get

uncaught securityerror: failed read 'contentdocument' property 'htmliframeelement': blocked frame origin "http://s.codepen.io" accessing frame origin "https://www.youtube.com". frame requesting access has protocol of "http", frame being accessed has protocol of "https". protocols must match.

i guess problem comes being logged 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

you can't. can access contents of iframe if content document has same origin page; since content document of iframe youtube, it'll different origin.

the error message bit misleading in identifies http/https mismatch problem. technically true, protocol part of origin, what's more relevant hostnames different.

the way capture events directed @ iframe place transparent element on frame; however, prevent events being passed frame @ all. (no, can't generate events yourself, or allow them propagated through element.) so, long story short, you'll need step , figure out way of accomplishing goals; there's no way way you're asking for.


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -