我正在創建一個應該創建嵌入式SWF的腳本,並且如果用戶沒有可用的Flash,也可以使用圖像作爲後備。由於我不被允許使用任何其他類似SWFobject的庫,所以我被困在使用DOM技術(如createElement/appendChild/setAttribute)中。使用createElement在IE8或更低版本中爲swf添加後備圖像?
我一直在使用這個偉大的博客文章:http://pipwerks.com/2011/05/30/using-the-object-element-to-dynamically-embed-flash-swfs-in-internet-explorer/作爲指導,我已經在我測試過的所有瀏覽器中運行Flash,但它不包含任何解決方案,以便我可以注入鏈接/圖像組合到Internet Explorer 8中的對象中。
使用createElement(「a」)和類似的圖像並將其添加到任何其他Div元素都可以正常工作,但是如果我嘗試將其注入到對象MSIE8拋出「無效參數」。
我也嘗試創建一個ID爲假的參數,並試圖用我的鏈接/圖像組合替換,並在我測試過的其他瀏覽器,但不是在IE8中工作。任何想法都將非常感激。
這是我的代碼(我用的JS和PHP組合創建腳本):
var alink = document.createElement("a");
alink.setAttribute("href", "URL_TO_TARGET_SITE_OR_CLICK_COUNTER");
var alinkImage = document.createElement("img");
alinkImage.setAttribute("src", "URL_TO_IMAGE");
alinkImage.setAttribute("alt", "");
alinkImage.setAttribute("width", "IMAGE_WIDTH");
alinkImage.setAttribute("height", "IMAGE_HEIGHT");
alink.appendChild(alinkImage);
if(!IE8) {
flashObject.appendChild(alink);
document.getElementById('ad_filler_placeholder').appendChild(flashObject);
} else {
/* this code will be executed if IE8 or lower, sadly appending alink into flashobject fails */
flashObject.appendChild(alink);
document.getElementById('ad_filler_placeholder').appendChild(flashObject);
}