How to capture onclick in iFrame for embedded YouTube video?

I have an iFrame that displays youtube embedded 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 on your tube video so that I can call http://myserver.com/dostuff rest api to update the external server counter, tracking the number of clicks and, of course, allow the video to play as expected.

Any information would be greatly appreciated.

+4
source share
3 answers

Everyone had great reviews. Thanks to everyone who posted. After hacking, the bottom line is that capturing the click event is not supported using html or javascript.

The best artifact and the cleanest solution I've found is here .

0
source

You can't, I suppose. This will be a security risk. If you basically want to track and something else, you probably would be best off doing something like adding an image / button instead of the video that the user clicks, resulting in a video.

Edit: This solution may also work ; I'm not sure if it will work for iframes that are not in the same domain.

+3
source

window.postMessage can help. But you must have access to the source code of the page that you are showing in the iframe. Therefore, in the case of the introduction of youtube video, you probably cannot handle it.

+1
source

All Articles