Reputation: 31
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>
Upvotes: 3
Views: 1982
Reputation: 31
I got bitten by this too. The Youtube iframe API needs the HTML5 postMessage feature, which IE7 and other old browsers do not have.
Upvotes: 1
Reputation: 11020
You should use double quotes in JSONs, because actually it is required to set string between double quotes. At height and width delete the single quotes and just write the integer, since it isn't a string.
Upvotes: 0