2012-04-05 78 views
0

我已經在使用swfobject的Youtube視頻的加載器。 使用的插件:jQuery 1.6.4 + SWFobject 2.2IE8的錯誤:腳本innerhtml加載

一切都很好的工作在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

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,有很多例子,在那裏,告訴你如何測試不同的瀏覽器版本。