Shpigford
Shpigford

Reputation: 25348

Can't set allowTransparency when using createElement for 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.com/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.com/page"></iframe>

Upvotes: 1

Views: 2386

Answers (2)

henser
henser

Reputation: 3327

Try this:

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

Upvotes: 8

Serj Sagan
Serj Sagan

Reputation: 30218

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

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

Your Javascript example seems correct.

Upvotes: -1

Related Questions