Right now I have youtube videos loading in via Iframe. Is it even possible to check if the youtube video ended when it is in that sort of state? Can I use OnStateChange() t
you can detect the end of the video like so:
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.ENDED){
// your code to run after video has ended
}
}
If you have an iframe
on your page, and its src
attribute contains a URL which does not have the same domain, protocol or port as the container page, you can not access its document
because of Same Origin Policy.
You may want to look into YouTube supporting postMessage().
If you do own the iframe
's contents, then get its iframe.contentDocument
where you can access the iframe
's document
.
Yes, but it's an experimental API:
https://developers.google.com/youtube/iframe_api_reference