Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > document.bgColor in Opera

Reply
Thread Tools

document.bgColor in Opera

 
 
Just One
Guest
Posts: n/a
 
      06-24-2007
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


 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      06-24-2007
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/
 
Reply With Quote
 
 
 
 
scripts.contact
Guest
Posts: n/a
 
      06-24-2007
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).backgroundCol or||'transparent');
menuDiv = menuDiv + '></div>';

 
Reply With Quote
 
Just One
Guest
Posts: n/a
 
      06-24-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> 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).backgroundCol or||'transparent');
> menuDiv = menuDiv + '></div>';



 
Reply With Quote
 
Randy Webb
Guest
Posts: n/a
 
      06-25-2007
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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparisons of IE, Opera and Firefox on DOM (Javascript/CSS) support(Opera wins) Bob HTML 24 05-21-2006 05:31 PM
Opera to Firefox bookmarks? Mason A. Clark Firefox 12 11-20-2004 08:17 AM
Firefox vs Opera? fresh Firefox 15 09-19-2004 07:30 PM
Opera 7.53 vs Opera 6.0 ? Hockey Buff Computer Support 3 08-17-2004 08:53 PM
Import Opera-Bookmarks Herbert A. Eberth Firefox 6 05-01-2004 05:03 AM



Advertisments