JavaScript

Youtube Embedding

Where I stumbled:

Working example is on the iframe API page. Briefly:

1. Have a div with an id.

<div id="player"></div>

2. Load the script…

tag = document.createElement('script')
tag.src = "https://www.youtube.com/iframe_api"
firstScriptTag = document.getElementsByTagName('script')[0]
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag)

3. Initialise:

window.onYouTubeIframeAPIReady = ->
  window.player = new YT.Player 'player',
    height: 390
    width: 640
    videoId: 'M7lc1UVf-VE'
    playerVars:
      controls: false
    events:
      onReady: ->
      onStateChange: ->
Standard