Skip to content

Instantly share code, notes, and snippets.

@run26kimo
Created March 6, 2013 04:04
Show Gist options
  • Save run26kimo/5096613 to your computer and use it in GitHub Desktop.
Save run26kimo/5096613 to your computer and use it in GitHub Desktop.
iframe 嵌入 Youtube auto play 自動播放 & mute 靜音
<iframe class="youtube-player" id="player" type="text/html" src="http://www.youtube.com/embed/EnErifh93hM?autoplay=1" height="400px" width="600px"></iframe>
<!-- 1. The <div> tag will contain the <iframe> (and video player) -->
<div id="player"></div>
<script> // 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
playerVars: { 'autoplay': 1, 'controls': 1,'autohide':1,'wmode':'opaque' },
videoId: 'JW5meKfy3fY',
events: {
'onReady': onPlayerReady}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.mute();
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment