View Full Version : Change bgcolor of frames pages

02-19-2007, 04:02 AM
I'm a newbie to javascript, but using my programming experience from other languages.

I've got a frames page. In the bottom frame is a table, with each cell having a different bgcolor. I can change the colour of the bottom page on mouseover with the following:

<td bgcolor="#cccccc" width="13"><B><A ONMOUSEOVER="document.bgColor='#cccccc'"><FONT SIZE=3>B</FONT></A></B></td>

What I want to do is to also change the top frame page's bgcolor.

I've tried(in the bottom page):
<td bgcolor="#cccccc" width="13"><B><A ONMOUSEOVER ="parent.top.recolourPage('#cccccc')"><FONT SIZE=3>B</B></FONT></A>

and (in the top page, <Head> section):
<script language="JavaScript" type="text/javascript">
function recolourPage(newcolor)

but this doesn't work.

The pages where I've put the code are footer.htm and header.htm
The frames are called top and bottom.


02-19-2007, 05:42 AM
The word top is a poor choice of name for a frame as, it is reserved to mean the top page or frameset.

There are at least two things wrong with your approach. First of all, bgcolor has been deprecated in favor of the css (scripted) style.backgroundColor. That isn't the real problem because bgcolor still works in most browsers for the body element. You have traversed up to the parent page (frameset) but not back down to the frame where you actually want to change the background color.

Try this:


02-19-2007, 03:20 PM
Thanks for your prompt reply, John.

The frame name 'top' was automatically allocated by Frontpage. I can change it if neccessary.

What I've got now is:

<td bgcolor="#cccccc" width="13"><B><A ONMOUSEOVER ="parent.window.frames.top.document.body.style.backgroundColor='red';"><FONT SIZE=3>B</B></FONT></A></td>
No error, but still doesn't work.:(
The page background in the top frame (src=Header.htm) doesn't change colour.

Do I have to refresh the top frame before it takes effect?
I would have thought that a refresh would bring it back with it's original colour!

Do I need any scripting in Header.htm for this to work?


02-19-2007, 05:17 PM
The frame name 'top' was automatically allocated by Frontpage. I can change it if neccessary.

It's necessary. You shouldn't have to refresh the page you are changing but, you need to refresh the page that changes it. To be on the safe side, use lower case, try:


Oh, and test the result in the browser, not in some FP preview mode. I got this working here with no problems. If this doesn't take care of it for you, give me a link to your problem pages.

02-19-2007, 11:48 PM

Changed 'top' to 'upper' as you suggested and it worked OK.:D

Thanks very much indeed.