tags:

views:

2184

answers:

4

Ok ie 8 does not want to play nice

i have a border showing on my iframe and cant get ride of it

IE 6 and 7 work as intended with a little javascript

function test(){
    var iframe=document.getElementById('frame2');
    iframe.contentWindow.document.body.style.backgroundColor="#a31d1d";
    iframe.contentWindow.document.body.style.border="#a31d1d";
    iframe.contentWindow.document.body.style.outlineColor="#a31d1d";
}

but ie 8 still showing it

A: 

Sample HTML to go with the sample JS would be helpful =)

Try using IE8's Developer Tools (press F12 on the page you have problems with) to isolate what styles are being applied to the iframe. You can also play with the styles there, to cut down your iteration time.

DDaviesBrackett
A: 

Keep in mind that this may be IE not respecting border settings in the css, whereas the traditional setting of the attribute BORDER=0 on the iframe element may work. Worth a test, at least.

Edit: It looks like what does fix the problem is setting frameborder='0' on the iframe element. That worked for me, at least.

Tchalvak
+2  A: 

Add following attributes to iframe tag: marginheight="0" marginwidth="0" frameborder="0"

Assaf Feldman
I tried using jQuery to add these in pragmatically but IE8 seems to just ignore them; after wasting too much time trying to hide a border (what a trivial task huh?) I went with the hard-coded attributes to force this for IE8. "why is IE so rubbish!?" is my favourite phrase today - and yes I am cross browser testing :-D. Hehe. Thanks for figuring this out!
widgisoft
FYI: Unfortunately adding a frameborder attribute inline in document will make the document to never validate for HTML 5. But there seem to be no other way around this issue.
Marco Demajo
+2  A: 

I had the same problem with iframes created dynamically, and it turned out that setting border properties AFTER adding the iframe to the document has NO effect:

The following code shows a 3d border:

var iframe = document.createElement("IFRAME");
iframe.src = "http:www.stackoverflow.com";
//Iframe added BEFORE setting border properties.
document.body.appendChild(iframe);
iframe.frameBorder = "no";

But this actually removes it:

var iframe = document.createElement("IFRAME");
iframe.src = "http:www.stackoverflow.com";
iframe.frameBorder = "no";
//Iframe added AFTER setting border properties.
document.body.appendChild(iframe);

Hope that this would help solve your problem.

MK