Last Updated: February 25, 2016
· zigotica

Add custom poster frame to youtube video without the API

The trick is adding the iframe in a comment. Javascript reads comment contents and saves iframe definition to a var. When user clicks on the image, javascript overwrites container innerHTML using the iframe defined in the comments.

This code is also valid in browsers not supporting window.postMessage (API uses postMessage).