Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture onclick within an iFrame for embedded YouTube video?

I have an iFrame that displays an embedded youtube video.

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

What I would like to do is somehow capture the click event when the user clicks the you tube video so that I can call an http://myserver.com/dostuff rest api to update an external server counter tracking the number of clicks and of course allow the video to play as expected.

Any information would be greatly appreciated.

like image 988
genxgeek Avatar asked Aug 09 '12 22:08

genxgeek


1 Answers

You can't, I believe. That would be a security risk. If you mainly want to do tracking and whatnot, you would probably be best off doing something like adding an image/button in the place of the video that the user clicks, causing the video to appear.

Edit: This solution may work too; I'm not sure if it'll work for iframes that aren't on the same domain.

like image 175
404 Not Found Avatar answered Nov 07 '22 18:11

404 Not Found