Results 1 to 5 of 5

Thread: Change bgcolor of frames pages

  1. #1
    Join Date
    Feb 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Change bgcolor of frames pages

    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)
    {document.bgColor=newcolor}
    </script>

    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.

    Help!!!!
    Thanks
    VBcoder

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,167
    Thanks
    44
    Thanked 3,240 Times in 3,201 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    parent.window.frames.frame_name.document.body.style.backgroundColor='red';
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Feb 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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?

    VBcoder

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,167
    Thanks
    44
    Thanked 3,240 Times in 3,201 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by vbcoder View Post
    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:

    Code:
    onmouseover="parent.window.frames.frame_name.document.body.style.backgroundColor='red';"
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Feb 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking

    John,

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

    Thanks very much indeed.

    VBcoder

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •