javascript - Can't set allowTransparency when using createElement for iframe - Stack Overflow

I'm doing document.createElement to insert an iframe, but I'm not able to set allowTransparen

I'm doing document.createElement to insert an iframe, but I'm not able to set allowTransparency. Here's the code I'm using:

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/page';
document.body.appendChild(iframe);

But the output, according to Web Inspector, is just:

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

I'm doing document.createElement to insert an iframe, but I'm not able to set allowTransparency. Here's the code I'm using:

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./page';
document.body.appendChild(iframe);

But the output, according to Web Inspector, is just:

<iframe class="example" frameborder="0" scrolling="no" style="width: 260px; height: 120px; border: none; " src="//example./page"></iframe>
Share Improve this question asked Feb 15, 2013 at 22:06 ShpigfordShpigford 25.4k61 gold badges167 silver badges262 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

Try this:

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

Have you tried this with jQuery? It would be as simple as

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

Your Javascript example seems correct.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745488771a4629891.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信