我使用swfobject为Youtube视频编写了一个加载器。使用的插件:jQuery 1.6.4 + SWFobject 2.2
一切都在IE8上运行良好! 它在script.innerHTML崩溃...
<div id"youtube"><div id="player"></div></div>
脚本
function loadYoutube(videoID)
{
var script = document.createElement("script");
script.type = "text/javascript";
document.getElementById("youtube").appendChild(script);
script.innerHTML = 'var params = { allowScriptAccess: "always", wmode: "transparent", allowfullscreen:"true" }; var atts = { id: "player" }; swfobject.embedSWF("http://www.youtube.com/v/'+videoID+'?enablejsapi=1&playerapiid=ytplayer&version=3", "player", "870", "550", "8", "flash/expressInstall.swf", null, params, atts);';
}
loadYoutube('BoEKWtgJQAU');
有什么想法吗?谢谢
IE8(我相信还有IE7)在innerHTML方面存在问题,如果您尝试以这种方式使用它,它将崩溃。我遇到了类似的问题,并使用.text而不是.innerHTML解决了它。
因为这只是IE8/IE7的问题,所以您应该输入一些逻辑来测试IE8/IE7并使用.text而不是.innerHTML。我正在使用jQuery,所以能够像这样测试IE8:
if ($.browser.msie && parseInt($.browser.version, 10) === 8) {
script.text = 'var params = { allowScriptAccess: "always", wmode: "transparent", allowfullscreen:"true" }; var atts = { id: "player" }; swfobject.embedSWF("http://www.youtube.com/v/'+videoID+'?enablejsapi=1&playerapiid=ytplayer&version=3", "player", "870", "550", "8", "flash/expressInstall.swf", null, params, atts);';
} else {
script.innerHTML = 'var params = { allowScriptAccess: "always", wmode: "transparent", allowfullscreen:"true" }; var atts = { id: "player" }; swfobject.embedSWF("http://www.youtube.com/v/'+videoID+'?enablejsapi=1&playerapiid=ytplayer&version=3", "player", "870", "550", "8", "flash/expressInstall.swf", null, params, atts);';
}
如果您不使用jQuery,则有许多示例可以向您展示如何测试不同的浏览器版本。