Created
October 7, 2016 00:02
-
-
Save renorram/ff54d05f081d47ad48a15bcaae399622 to your computer and use it in GitHub Desktop.
Sending commands to youtube iframe.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.callPlayer = function (iframe, func, args) { | |
var iframe = document.getElementById(iframe); | |
var src = iframe.getAttribute('src'); | |
if (src && src.indexOf('youtube.com/embed') !== -1) { | |
iframe.contentWindow.postMessage(JSON.stringify({ | |
'event': 'command', | |
'func': func, | |
'args': args || [] | |
}), '*'); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment