views:

593

answers:

3

I am trying to insert an iframe into the browser DOM via javascript and want to remove the border if IE but can't seem to. I have tried these to no avail:

iframeElement.style.borderStyle="none";

and

iframeElement.style.frameBorder = "0";

Any suggestions will be much appreciated.

A: 

Try iframeElement.style.borderCollapse = 1; or iframeElement.style.borderWidth = 0;

Anatoliy
They don't work both on IE8 and IE7.
Marco Demajo
+1  A: 

The frameBorder attribute exists directly on the iframe element, is not a CSS property.

Try with:

iframeElement.frameBorder = 0;
CMS
Gah, I've downvoted this, done some more research and realised this answer isn't entirely wrong (see my answer for clarification) but apparently cannot remove my downvote unless this answer is edited. Sorry.
Tim Down
@Tim: Don't worry, edited in case you want to remove your downvote, I added a link to the frameBorder attribute on the DOM Core Level 2 specification...
CMS
@CMS: Done, thanks.
Tim Down
+2  A: 

Bizarrely, I was looking for an answer to this very issue myself earlier today. I found that setting the frameBorder to 0 property does work, so long as you do it before the iframe is added to the document.

var iframe = document.createElement("iframe");
iframe.frameBorder = 0;
document.body.appendChild(iframe);
Tim Down
+1 very interesting. IE8 still have the same problem, can you belive this!? Adding frameBorder inline makes the document not to validate anymore for HTML 5 so the only trcik is to add it via JS as you suggest.
Marco Demajo
+1 same here, the ordering thing was a big problem.
Pedro