【发布时间】: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>
【问题讨论】:
-
刚刚找到这篇关于如何在 IE6 中修复 JSON stackoverflow.com/questions/1787020/json-object-in-ie6-how的旧帖子
标签: javascript api youtube