IE8 bug:脚本innerhtml加载

时间:2012-04-05 12:56:21

标签: youtube-api innerhtml swfobject

我使用swfobject为Youtube视频工作过。 使用的插件:jQuery 1.6.4 + SWFobject 2.2

一切都在IE8上表现出色!它崩溃在script.innerHTML ......

<div id"youtube"><div id="player"></div></div>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

SCRIPT

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')​​​;​

有什么想法吗? 感谢

1 个答案:

答案 0 :(得分:1)

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,那么有很多示例可以向您展示如何测试不同的浏览器版本。