Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Youtube iFrame Api Example - Error : "JSON is undefined"?

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>
like image 731
alexis Avatar asked Jun 06 '26 12:06

alexis


1 Answers

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

like image 143
adittes Avatar answered Jun 09 '26 02:06

adittes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!