2013-02-15 13 views
0

我在做document.createElement來插入iframe,但我無法設置allowTransparency。下面是我使用的代碼:使用createElement for iframe時無法設置allowTransparency

var iframe = document.createElement('iframe'); 
iframe.className = 'example'; 
iframe.allowTransparency = 'true'; 
iframe.frameBorder = '0'; 
iframe.scrolling = 'no'; 
iframe.style.width = '260px'; 
iframe.style.height = '120px'; 
iframe.style.border = 'none'; 
iframe.src = '//example.com/page'; 
document.body.appendChild(iframe); 

但產量,根據Web檢查,只是:

<iframe class="example" frameborder="0" scrolling="no" style="width: 260px; height: 120px; border: none; " src="//example.com/page"></iframe> 

回答

3

試試這個:

iframe.setAttribute('allowtransparency', 'true'); 
+0

這是否有訣竅? – henser 2013-02-15 22:26:01

-1

你有沒有使用jQuery試過嗎?它會像

$(".example").attr("allowTransparency", "true"); 

您的Javascript示例似乎正確。

+0

不使用jQuery。 – Shpigford 2013-02-15 22:11:48