如何将 youtube 嵌入式播放器设置为在单击时取消静音。您可以在http://www.harvestarmy.org主页上看到我所指的嵌入式播放器。它是右侧的那个,上面写着“来自 YouTube 的最新视频。我将其设置为默认静音,但我希望它在有人点击时自动取消静音。
这是我使用的代码:
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="player"></div>
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
// This is a protocol-relative URL as described here:
// http://paulirish.com/2010/the-protocol-relative-url/
// If you're testing a local page accessed via a file:/// URL, please set tag.src to
// "https://www.youtube.com/iframe_api" instead.
tag.src = "//www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. …Run Code Online (Sandbox Code Playgroud)