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

I try the new iFrame Api examlpe @ http://code.google.com/apis/youtube/iframe_api_reference.html (code below here ..)

All works on Chrome, Safari, but there are error messages in firefox 3.0 and IE6 -> JSON undefined on line: 13 The player is still working, but the javascript crashes completely.

I tried to get the json2.js library (http://www.json.org/) script on top of the page, but nothing works better. How can I arrange this JSON error for 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>
+3
source share
2 answers

I was bitten too. The Youtube iframe API needs an HTML5 postmessage function that does not have IE7 and other older browsers.

Source

+1

JSON, . , .

0

All Articles