Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML - Desktop background question

Status
Not open for further replies.

Xyphious

MIS
May 6, 2008
42
GB
Hi all,

i've created a little desktop widget for my company that scrolls server alerts to user desktops.

In my organisation we don't have unified desktop settings so i've got users with different colors complaining about the color i've used.
My question is, is there any code in existance i can use which will allow a dynamic background color, i doubt there is anything as it'd require reading windows settings but figured i'd wrack some brains.

Just so you know i'm simply using the basic <BODY bgcolor="#3A6EA5"> to define the color, open to any suggestions though


Thanks in advance

______________________________________________

--If something's worth doing, its worth doing right - HST RIP--
 
You can use Javascript for this - there isn't much information you can get but the following properties might help you out.

screen.colorDepth

You'll need to give your body tag an ID and attach an onload event to it...

In this example, the background color is initially set to #3A6EA5, and the setColor event is called. If the screen color depth (sc) is 32 (32 bit), leave it as is, otherwise change it to white (#FFFFFF).

The reason you set it initially is in case of browsers that have javascript turned off, it will stay at your inital setting.

Code:
<html>
<head>
<script language="javascript">
function setColor() {
	obj = document.getElementById("myBodyTag");
	sc = screen.colorDepth;
	obj.style.background = (sc == "32") ? "#3A6EA5" : "#FFFFFF";
}
</script></head>
<body id="myBodyTag" style="background:#3A6EA5;" onload="setColor();" >
...
</body>
</html>

Here are the rest of the properties, in case you want to use width or height of the scrren




TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
Hi

vicvirk, there is a single [tt]body[/tt] element in the whole [tt]document[/tt], why to identify it with an [tt]id[/tt] ?
Code:
function setColor() {
    sc = screen.colorDepth;
    [red]document.body[/red].style.background = (sc == "32") ? "#3A6EA5" : "#FFFFFF";
}

Feherke.
 
feherke,

I just try to make it a habit to identify major element with an ID - true you don't need it, but I personally don't like to mix up my references to the elements - I prefer using getElementById...

I also use the dollar sign function which the coding standard across the sites...

Personal preference, that's all...




TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
^ sorry, meant to write:

I also use the dollar sign function which standardizes the coding across the sites...


TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
Thats great, thanks for the replies all. If i get a moment away from clients today i'll sit down and investigate

Appreciate the input from all of you

Cheers

______________________________________________

--If something's worth doing, its worth doing right - HST RIP--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top