自动播放Youtube视频在全屏,然后重定向



我在使用youtube api完成播放后重定向youtube视频时遇到了麻烦。我有css代码的样式,但这并不重要,在这种情况下。任何帮助都将不胜感激。编辑:我希望这是回应。下面是我的代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
  <HEAD>
    <LINK href="style.css" rel="stylesheet" type="text/css">
  </HEAD>
  <BODY>
   <div class="video-container">
         <iframe src="http://www.youtube.com/embed/sOS9aOIXPEk?autoplay=1" frameborder="0" width="560" height="315"></iframe>
</div>
</HTML>
    <div id="player"></div>
    <script>
    var tag = document.createElement('script');
    tag.src = "http://www.youtube.com/iframe_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
        // create youtube player
        var player;
        function onYouTubePlayerAPIReady() {
            player = new YT.Player('player', {
             height=''
             width=''
              videoId: '0Bmhjf0rKe8',
              playerVars:{'rel':0,'showinfo':1,'autoplay':1}
              events: {
                'onStateChange': onPlayerStateChange
              }
            });
        }

        // when video ends
        function onPlayerStateChange(event) {        
            if(!event.data)          
                GoHome();
        }
        function GoHome(){
            window.location = 'http://www.google.com';
        }

    </script>

当视频结束时。数据== 2。您还遗漏了一些逗号作为对象条目的分隔符。下面是一个工作示例(注意:第一个iframe被注释掉了):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
  <HEAD>
    <LINK href="style.css" rel="stylesheet" type="text/css">
  </HEAD>
  <BODY>
<!--
   <div class="video-container">
    <iframe src="http://www.youtube.com/embed/sOS9aOIXPEk?autoplay=1" frameborder="0" width="560" height="315"></iframe>
</div>
-->
    <div id="player"></div>
    <script>
    var tag = document.createElement('script');
    tag.src = "http://www.youtube.com/iframe_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
        // create youtube player
        var player;
        function onYouTubePlayerAPIReady() {
            player = new YT.Player('player', {
               height: '768',
               width: '1024',
               videoId: '0Bmhjf0rKe8',
               playerVars:{'rel':0,'showinfo':1,'autoplay':1},
               events: {
                'onStateChange': onPlayerStateChange
              }
            });
        }

        // when video ends
        function onPlayerStateChange(event) {
          //alert (event.data);
          if (event.data == 0)
                  GoHome();
        }
        function GoHome(){
            window.location = 'http://www.google.com';
        }
    </script>
</BODY>
</HTML>

相关内容

  • 没有找到相关文章

最新更新