I’ve been trying to get the YouTube JS API’s stopVideo() method to work for some time now. Everyone says it’s as simple as calling it on the iframe element, but the only way I was able to get it to work was via a method called postMessage() which I found on someone else’s Stackoverflow post.
The code:
$('iframe').postMessage('{"event":"command","func":"stopVideo","args":""}', '*')
is what eventually got it working for me. But still, I don’t understand what I’m doing. Can anyone explain this to me?
From MDN postMessage
So what it does is lets you get around the same origin policy and talk to other domains. Only issue, not all browsers support it.