View Full Version : Using Java Script to remove an iframe border

Dec 20th, 2011, 03:20 AM
I found this thread here on CodingForums regarding the use of Java Script to implement an iframe on a page, while at the same time remove its border: http://www.codingforums.com/showthread.php?t=140363

var iframe = document.createElement("iframe");
iframe.id = "flashlatest1";
iframe.width = "419";
iframe.height = "240";
iframe.src = "pageURL";
// i did try the following line instead which didn't work...
//iframe.frameBorder = "0";
iframe.scrolling = "no";

I'm not very familiar with java script. For this to work, do I need to create an element for each: id, width, height, src, etc.?

Also, would this script simply be placed between tags like these on my page?
<script type="text/javascript"> and </script>

A bit of direction would be appreciated.


Dec 20th, 2011, 03:54 AM
Let me ask a question which may have religious implications...

Why are you implementing an iframe via JS, rather than <iframe> in html with its associated attributes (like "frameborder")


Dec 20th, 2011, 03:57 AM
Probably because of validation issues?

Dec 20th, 2011, 04:04 AM
I was wondering that, but surely (actually I'm asking this as a question) if an html iframe has validation issues, doing the same thing by stuffing an iframe in via the DOM is equivalent to sticking one's head in the sand?


Dec 20th, 2011, 04:33 AM
Hi Dave,

This really bites. Why does IE have to be like this? I've resorted to using border="0" in the html iframe code.

I know what you mean about sticking one's head in the sand, but I just thought if it could be done with js, why not give it a try.