Skip to content

Instantly share code, notes, and snippets.

@chriscoyier
Created January 24, 2014 17:20
Show Gist options
  • Save chriscoyier/8601875 to your computer and use it in GitHub Desktop.
Save chriscoyier/8601875 to your computer and use it in GitHub Desktop.
<html class=""><head><meta charset="UTF-8">
<script src="http://s.ytimg.com/yts/jsbin/www-widgetapi-vfl5O9lF3.js" async=""></script><script src="//www.youtube.com/player_api"></script><script style="display: none !important;"> function getSafeJS(js) { js = js.replace(/location(s+)?=/mi, ''); js = js.replace(/top.location.+=('|")/mi, ''); js = js.replace(/location.replace/mi, ''); js = js.replace(/window(s+)?\[(s+)?("|')l/mi, ''); js = js.replace(/self(s+)?\[(s+)?("|')loc/mi, ''); return js; } _ogEval = window.eval; window.eval = function(text) {_ogEval(getSafeJS(text));}; window.innerWidth = window.outerWidth; // Fixes browser bug with it innerWidth reports 0 window.innerHeight = window.outerHeight; // Fixes browser bug with it innerHeight reports 0 </script>
<style></style></head><body>
<iframe id="video" width="640" height="480" src="//www.youtube.com/embed/FKWwdQu6_ok?enablejsapi=1" frameborder="0" allowfullscreen=""></iframe>
<script>// global variable for the player
var player;
// this function gets called when API is ready to use
function onYouTubePlayerAPIReady() {
// create the global player from the specific iframe (#video)
player = new YT.Player('video', {
events: {
// call this function when player is ready to use
'onReady': onPlayerReady
}
});
}
function onPlayerReady(event) {
// play the video
event.target.playVideo();
}
// Inject YouTube API script
var tag = document.createElement('script');
tag.src = "//www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
//@ sourceURL=pen.js</script>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment