I have a page with an iframe which load a youtube video (the src of iframe is modified in runtime). I based on code by Rob W provided in different answers on this topic
onYouTubePlayerAPIReady should be on the window object.
onYouTubePlayerAPIReady
window
try:
window.onYouTubePlayerAPIReady = function() { alert('called onYouTubePlayerAPIReady'); ytIframeplayer = new YT.Player('browser', { events: { "onStateChange": stopCycle } }); }