【问题标题】:Displaying iframe with javascript/jquery使用 javascript/jquery 显示 iframe
【发布时间】:2013-03-01 11:00:34
【问题描述】:

我有这个 iframe:

<iframe width="0" height="0" src="http://www.youtube.com/embed/Nc9xq-TVyHI?autoplay=1&start=110&end=119" frameborder="0" ></iframe></body></html>';

我需要在一些 javascript/jquery 事件上显示/执行这个 iframe。 我的问题是如何使用 javascript/jquery 代码显示该 iframe?

提前致谢!

【问题讨论】:

    标签: javascript jquery jquery-ui youtube-api youtube-javascript-api


    【解决方案1】:

    $('#divToPutItIn').html('html here');

    【讨论】:

    • 只有当 div 标签在带有 jquery 代码的
    • $('document').ready(function() { $('#divToPutItIn').html('html here'); }); 可能会为您解决问题
    【解决方案2】:

    你需要为此学习 Youtube API .. 你会得到答案 here ..

    以及下面的演示链接

    var player;
      function onYouTubeIframeAPIReady() {
        player = new YT.Player('player', {
          height: '390',
          width: '640',
          videoId: 'u1zgFlCw8Aw',
          events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange
          }
        });
      }
    
      // 4. The API will call this function when the video player is ready.
      function onPlayerReady(event) {
        event.target.playVideo();
      }
    

    http://jsfiddle.net/rushijogle/TDNm5/1/

    【讨论】:

      【解决方案3】:

      如果您有时间学习如何正确使用 JavaScript,即在您的 YouTube 视频中使用 JavaScript,那么它是在 iframe 中提供给您的这一事实是无关紧要的。只需从YouTube JavaScript Player API 页面学习示例。一旦您按照他们的连接过程进行操作,他们就会在底部演示您的 javascript 应该是什么样子。

      如果您采用其他任何方式,您的视频可能会遇到问题或需要其他功能。我从经验中知道。

      【讨论】:

      • 你说得对,最好学习YouTube播放器API,我去看看
      猜你喜欢
      • 2011-05-04
      • 1970-01-01
      • 1970-01-01
      • 2012-06-02
      • 1970-01-01
      • 2018-07-28
      • 2017-03-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多