document.bgColor in Opera

Discussion in 'Javascript' started by Just One, Jun 24, 2007.

  1. Just One

    Just One Guest

    Hi,

    I'm trying to dynamically assign a div background the value of the document
    background with a code like this:

    var menuDiv = '<div style="visibility:hidden; ';
    menuDiv = menuDiv + 'background-color:';
    menuDiv = menuDiv + document.bgColor;
    menuDiv = menuDiv + '></div>';

    In IE and FF, that's working great but not in Opera. I don't really think
    Opera is very popular but still, I'm wondering if what I want is easily
    achievable with this browser?

    Thanks
     
    Just One, Jun 24, 2007
    #1
    1. Advertising

  2. Just One

    Randy Webb Guest

    Just One said the following on 6/24/2007 9:08 AM:
    > Hi,
    >
    > I'm trying to dynamically assign a div background the value of the document
    > background with a code like this:
    >
    > var menuDiv = '<div style="visibility:hidden; ';
    > menuDiv = menuDiv + 'background-color:';
    > menuDiv = menuDiv + document.bgColor;


    document.style.backgroundColor;

    And then make sure it is defined as background-color in the CSS of the
    body element.
    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, Jun 24, 2007
    #2
    1. Advertising

  3. Just One wrote:
    > Hi,
    >
    > I'm trying to dynamically assign a div background the value of the document
    > background with a code like this:
    >
    > var menuDiv = '<div style="visibility:hidden; ';
    > menuDiv = menuDiv + 'background-color:';
    > menuDiv = menuDiv + document.bgColor;
    > menuDiv = menuDiv + '></div>';


    Randy's suggestion will not work, try this:

    var menuDiv = '<div style="visibility:hidden; ';
    menuDiv = menuDiv + 'background-color:';
    menuDiv = menuDiv +
    (document.bgColor||
    getComputedStyle(document.body,null).backgroundColor||'transparent');
    menuDiv = menuDiv + '></div>';
     
    scripts.contact, Jun 24, 2007
    #3
  4. Just One

    Just One Guest

    Cheers, scripts.contact! That works great, even though I don't quite know,
    let alone understand that method. I guess being stuck with JS1.3 and old
    browsers is the reason, have to fast-forward to version 1.5 and Gecko-based
    DOM (as I understand both FF and Opera try adhering to it).

    "scripts.contact" <> wrote in message
    news:...
    > Just One wrote:
    > > Hi,
    > > I'm trying to dynamically assign a div background the value of the

    document
    > > background with a code like this:
    > > var menuDiv = '<div style="visibility:hidden; ';
    > > menuDiv = menuDiv + 'background-color:';
    > > menuDiv = menuDiv + document.bgColor;
    > > menuDiv = menuDiv + '></div>';

    >
    > Randy's suggestion will not work, try this:
    > var menuDiv = '<div style="visibility:hidden; ';
    > menuDiv = menuDiv + 'background-color:';
    > menuDiv = menuDiv +
    > (document.bgColor||
    > getComputedStyle(document.body,null).backgroundColor||'transparent');
    > menuDiv = menuDiv + '></div>';
     
    Just One, Jun 24, 2007
    #4
  5. Just One

    Randy Webb Guest

    scripts.contact said the following on 6/24/2007 2:51 PM:
    > Just One wrote:
    >> Hi,
    >>
    >> I'm trying to dynamically assign a div background the value of the document
    >> background with a code like this:
    >>
    >> var menuDiv = '<div style="visibility:hidden; ';
    >> menuDiv = menuDiv + 'background-color:';
    >> menuDiv = menuDiv + document.bgColor;
    >> menuDiv = menuDiv + '></div>';

    >
    > Randy's suggestion will not work


    Only because it should have been document.body.style.backgroundColor

    --
    Randy
    Chance Favors The Prepared Mind
    comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
     
    Randy Webb, Jun 25, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cliff Cavin

    Change BgColor of aspx page in code

    Cliff Cavin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    7,223
    Cliff Cavin
    Jan 19, 2004
  2. Peter Merwood

    bgcolor attribute not consistent between PCs

    Peter Merwood, Jan 28, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    361
    Hermit Dave
    Jan 28, 2004
  3. =?Utf-8?B?SkM=?=

    Changing DataGrid Item BGCOLOR

    =?Utf-8?B?SkM=?=, Mar 5, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    356
    =?Utf-8?B?SkM=?=
    Mar 6, 2004
  4. Bob
    Replies:
    24
    Views:
    1,546
  5. Nat
    Replies:
    0
    Views:
    135
Loading...

Share This Page