views:

1249

answers:

1

I am working on a Joomla 1.5 website and a little self-contained php application, which I want to show within an IFRAME inserted in an article. The template I am using for the website has a dark grey background and the IFRAME shows grey background when loaded in Firefox (I don't quite know why this is so, but I like it like this). However, when the page is loaded in IE, the IFRAME has white background (understandably).

How can I make the IFRAME copy the background color of its parent document also in IE?


Also, I have another unanswered question related to IFRAME usage and Joomla 1.5, which I would like to point your attention to.

+1  A: 

If the self-contained application is on the same domain as the article page, you could access the top frame (with the article) through javascript - like this:

document.body.style.backgroundColor = getComputedStyle(window.top.document.body);

Computed style can be get as described in this article.

Your other option is to add a query string parameter for the iframe, like bgcolor= - this is a more widget-like approach, and will make the stand-alone application more configurable. I personally recommend this approach - it will not rely on javascript and it will not flicker if the execution gets slow.

Alexander Gyoshev
thanks for the advice. Yes, the application is on the same domain and I will try the javascript solution, although I see why the second option has your preference.
Peter Perháč
first option won't work on IE, which uses currentStyle instead, and older browsers where neither is available. It also relies on the background being set on the body tag only; if it were set on the html tag or any other div inside the body it'd not work. The `bgcolor` parameter, on the other hand, is explicit and solid.
bobince
@bobince good point about the body tag - the currentStyle/computedStyle difference is explained in the article - I just used the term to describe the concept...
Alexander Gyoshev