YouTube上的iFrame API示例 - 错误:" JSON是不确定的"? [英] Youtube iFrame Api Example - Error : "JSON is undefined"?

查看:391
本文介绍了YouTube上的iFrame API示例 - 错误:" JSON是不确定的"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想新的iFrame阿比examlpe @
HTTP://$c$c.google.com/apis/youtube/iframe_api_reference html的(code下面在这里..)

万物工作prerfect在Chrome,Safari,但有一个错误在Firefox 3.0和IE6报告
- > JSON未定义在线:13
玩家依旧是工作,但JavaScript的完全崩溃。

我试图让在页面顶部json2.js库(http://www.json.org/)脚本,但没有效果更好。
我如何安排这些旧的浏览器这个JSON错误?

 < HTML和GT;
  <身体GT;
    &所述;! - 1的< DIV>标签将包含在<&IFRAME GT; (和视频播放器) - GT;
    < D​​IV ID =玩家>< / DIV>
    <脚本SRC =JS / json2.js>< / SCRIPT>
    < SCRIPT LANGUAGE =JavaScript的>
      // 2.本code加载的iFrame播放器API code异步。
      var标记=使用document.createElement('脚本');
      tag.src =htt​​p://www.youtube.com/player_api;
      VAR firstScriptTag = document.getElementsByTagName('脚本')[0];
      firstScriptTag.parentNode.insertBefore(标签,firstScriptTag);      // 3.本函数创建一个< IFRAME> (和YouTube播放器)
      // API的code下载后。
      VAR的球员;
      功能onYouTubePlayerAPIReady(){
        玩家=新YT.Player('球员',{
          高度:'390',
          宽度:'640',
          VIDEOID:u1zgFlCw8Aw',
          playerVars:{'自动播放':1,'控制':0,'showinfo':0,'循环':1,'相对':0,'showsearch':0,'enablejsapi':1},
          事件:{
            'onReady':onPlayerReady,
            onStateChange':onPlayerStateChange
          }
        });
      }      当视频播放器准备就绪// 4. API会调用这个函数。
      功能onPlayerReady(事件){
        event.target.playVideo();
      }
      功能onPlayerStateChange(事件){
        //
      }    < / SCRIPT>
  < /身体GT;
< / HTML>


解决方案

我被这个被咬了。在YouTube的iframe API需要HTML5 postMessage的功能,IE7等老的浏览器不具备的。

来源

I'm trying the new iFrame Api examlpe @ http://code.google.com/apis/youtube/iframe_api_reference.html (Code Below here..)

Everythings work prerfect on Chrome, safari but there is an Error reporting on firefox 3.0 and IE6 -> JSON is undefined on line:13 The player is still working but javascript crash completely.

I tried to get json2.js library (http://www.json.org/) script on top of page but nothing works better. How can I arrange this JSON Error on these old browsers ?

<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>

解决方案

I got bitten by this too. The Youtube iframe API needs the HTML5 postMessage feature, which IE7 and other old browsers do not have.

Source

这篇关于YouTube上的iFrame API示例 - 错误:&QUOT; JSON是不确定的&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆