More of an "answer" than a "question", but not having found this elsewhere I'm posting it here.
I was having difficulty initializing the iFrame API in all versions of IE and Firefox, with a somewhat custom implementation. Basically, it would load the API, but wouldn't create the player object.
After a bit of trial and error, I finally figured out it wasn't working because the div
ID I was passing to the object had its CSS visibility set to 'none'
. Once it was set to 'visible'
the whole thing worked. After that I tried setting the div
CSS to 'display:none'
(the app required the video to be hidden until requested by the user) which also caused the iFrame API to fail silently (never calling back 'onPlayerReady'
).
So, long story short, when using the YouTube iFrame API to initialize on a div
that you want to remain hidden until later, use a CSS technique like absolute positioning to push it off screen until you want it later. Also, found that once the player object is initialized and 'onPlayerReady'
has been called you could turn display on and off all day long and everything would still work as expected.
display: none
on the player (or a container), the player is effectively purged by the browser. You would not be able to later setdisplay: inline
and reuse the same player instance. Moving the player out of the viewport is the answer here, too. – Sweatband