• <i id='5oyyX'><tr id='5oyyX'><dt id='5oyyX'><q id='5oyyX'><span id='5oyyX'><b id='5oyyX'><form id='5oyyX'><ins id='5oyyX'></ins><ul id='5oyyX'></ul><sub id='5oyyX'></sub></form><legend id='5oyyX'></legend><bdo id='5oyyX'><pre id='5oyyX'><center id='5oyyX'></center></pre></bdo></b><th id='5oyyX'></th></span></q></dt></tr></i><div id='5oyyX'><tfoot id='5oyyX'></tfoot><dl id='5oyyX'><fieldset id='5oyyX'></fieldset></dl></div>
      <bdo id='5oyyX'></bdo><ul id='5oyyX'></ul>
    <legend id='5oyyX'><style id='5oyyX'><dir id='5oyyX'><q id='5oyyX'></q></dir></style></legend>
  • <tfoot id='5oyyX'></tfoot>

    1. <small id='5oyyX'></small><noframes id='5oyyX'>

        Youtube iframe api 未触发 onYouTubeIframeAPIReady

        Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)

        <small id='dVJAr'></small><noframes id='dVJAr'>

          <tfoot id='dVJAr'></tfoot><legend id='dVJAr'><style id='dVJAr'><dir id='dVJAr'><q id='dVJAr'></q></dir></style></legend>
            <bdo id='dVJAr'></bdo><ul id='dVJAr'></ul>
            1. <i id='dVJAr'><tr id='dVJAr'><dt id='dVJAr'><q id='dVJAr'><span id='dVJAr'><b id='dVJAr'><form id='dVJAr'><ins id='dVJAr'></ins><ul id='dVJAr'></ul><sub id='dVJAr'></sub></form><legend id='dVJAr'></legend><bdo id='dVJAr'><pre id='dVJAr'><center id='dVJAr'></center></pre></bdo></b><th id='dVJAr'></th></span></q></dt></tr></i><div id='dVJAr'><tfoot id='dVJAr'></tfoot><dl id='dVJAr'><fieldset id='dVJAr'></fieldset></dl></div>
                <tbody id='dVJAr'></tbody>

                • 本文介绍了Youtube iframe api 未触发 onYouTubeIframeAPIReady的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我已经与 youtube iframe api 斗争了很长一段时间了.不知何故,方法 onYouTubeIframeAPIReady 并不总是被触发.

                  I've been battling with the youtube iframe api for quite some time now. Somehow the method onYouTubeIframeAPIReady is not always triggered.

                  从症状来看,似乎是加载问题.检查器中没有显示错误.

                  From the symptoms it seems a loading problem. No errors are shown in the inspector.

                  这是我的代码:

                  <div id="player"></div>
                            <script>
                              videoId = 'someVideoId';
                              var tag = document.createElement('script');
                              tag.src = "//www.youtube.com/iframe_api";
                              var firstScriptTag = document.getElementsByTagName('script')[0];
                              firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
                            </script>
                  

                  JS

                  (在页面末尾调用.我尝试将代码放在上面的脚本之后,结果是一样的.)

                  JS

                  (called at the end of the page. I tried to place the code right after the above script and the result was the same.)

                  var isReady = false
                    , player
                    , poster
                    , video;
                  
                  $(function () {
                  $('.js-play').click(function (e) {
                      e.preventDefault();
                      interval = setInterval(videoLoaded, 100);
                    });
                  });
                  function onYouTubeIframeAPIReady() {
                    console.log(videoId)
                    player = new YT.Player('player', {
                      height: '445',
                      width: '810',
                      videoId: videoId,
                      events: {
                        'onReady': onPlayerReady//,
                        //'onStateChange': onPlayerStateChange
                      }
                    });
                  }
                  
                  function onPlayerReady(event) {
                    isReady = true;
                    console.log("youtube says play")
                  }
                  
                  function videoLoaded (){
                    if (isReady) {
                        console.log("ready and play")
                        poster.hide();
                        video.show();
                  
                        $('body').trigger('fluidvideos');
                  
                        player.playVideo();
                        clearInterval(interval);
                    } 
                  }
                  

                  问题在于,有时 console.log 没有打印任何内容,也没有任何反应.

                  The problem is that sometimes nothing gets printed by the console.log and nothing happens.

                  在手机上,这种情况一直都在发生.有什么想法吗?

                  On mobile phones this happens all the time. Any ideas?

                  推荐答案

                  这不是超时问题,你应该不需要手动触发这个函数.

                  It is not a timeout issue, and you should not need to fire this function manually.

                  确保您的 onYouTubeIframeAPIReady 函数在全局级别可用,而不是嵌套(隐藏)在另一个函数中.

                  Make sure your onYouTubeIframeAPIReady function is available at the global level, not nested (hidden away) within another function.

                  这篇关于Youtube iframe api 未触发 onYouTubeIframeAPIReady的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                  How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                  How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                  How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)
                  How to get number of video views with YouTube API?(如何使用 YouTube API 获取视频观看次数?)
                  Stop embedded youtube iframe?(停止嵌入 youtube iframe?)

                    <small id='7doFu'></small><noframes id='7doFu'>

                        <tbody id='7doFu'></tbody>

                          <tfoot id='7doFu'></tfoot>
                        1. <i id='7doFu'><tr id='7doFu'><dt id='7doFu'><q id='7doFu'><span id='7doFu'><b id='7doFu'><form id='7doFu'><ins id='7doFu'></ins><ul id='7doFu'></ul><sub id='7doFu'></sub></form><legend id='7doFu'></legend><bdo id='7doFu'><pre id='7doFu'><center id='7doFu'></center></pre></bdo></b><th id='7doFu'></th></span></q></dt></tr></i><div id='7doFu'><tfoot id='7doFu'></tfoot><dl id='7doFu'><fieldset id='7doFu'></fieldset></dl></div>
                          <legend id='7doFu'><style id='7doFu'><dir id='7doFu'><q id='7doFu'></q></dir></style></legend>
                            <bdo id='7doFu'></bdo><ul id='7doFu'></ul>