【问题标题】:Youtube iFrame Api Example - Error : "JSON is undefined"?Youtube iFrame Api 示例 - 错误:“JSON 未定义”?
【发布时间】:2011-07-14 21:48:48
【问题描述】:

我正在尝试新的 iFrame Api 示例 @ http://code.google.com/apis/youtube/iframe_api_reference.html(此处为代码..)

在 Chrome、safari 上一切正常,但在 firefox 3.0 和 IE6 上报告错误 -> JSON 在第 13 行未定义 播放器仍在工作,但 javascript 完全崩溃。

我尝试在页面顶部获取 json2.js 库 (http://www.json.org/) 脚本,但没有更好的方法。 如何在这些旧浏览器上安排此 JSON 错误?

<html>
  <body>
    <!-- 1. The <div> tag will contain the <iframe> (and video player) -->
    <div id="player"></div>
    <script src="js/json2.js"></script>
    <script language="javascript">
      // 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', {
          height: '390',
          width: '640',
          videoId: 'u1zgFlCw8Aw',
          playerVars: { 'autoplay': 1, 'controls': 0, 'showinfo': 0, 'loop': 1, 'rel' : 0, 'showsearch' : 0, 'enablejsapi' : 1},
          events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange
          }
        });
      }

      // 4. The API will call this function when the video player is ready.
      function onPlayerReady(event) {
        event.target.playVideo();
      }


      function onPlayerStateChange(event) {
        //
      }

    </script>
  </body>
</html>

【问题讨论】:

标签: javascript api youtube


【解决方案1】:

您应该在 JSON 中使用双引号,因为实际上需要在双引号之间设置字符串。 在高度和宽度处删除单引号并只写整数,因为它不是字符串。

【讨论】:

    【解决方案2】:

    我也被这个咬了。 Youtube iframe API 需要 HTML5 postMessage 功能,IE7 和其他旧浏览器没有。

    Source

    【讨论】:

      猜你喜欢
      • 2015-03-24
      • 1970-01-01
      • 1970-01-01
      • 2013-12-22
      • 2018-03-17
      • 2017-09-26
      • 2012-04-04
      • 2023-03-30
      • 1970-01-01
      相关资源
      最近更新 更多