473,706 Members | 3,907 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get background color from IE in rgb format?

We've got some JavaScript code that gets the current background color.
It works, but Netscape returns it in rgb format, while IE returns it as
the color
text name (e.g., 'white'). We need to do some math calculations on the
color,
so I want the rgb values. How can I get IE to return the background
color in rgb
format, or how do I convert the text color to its rgb value? Thanks!

May 19 '06 #1
8 12420
Here's a link that may help
http://web.njit.edu/~kevin/rgb.txt.html

<te*****@ucia.g ov> wrote in message
news:11******** **************@ y43g2000cwc.goo glegroups.com.. .
We've got some JavaScript code that gets the current background color.
It works, but Netscape returns it in rgb format, while IE returns it as
the color
text name (e.g., 'white'). We need to do some math calculations on the
color,
so I want the rgb values. How can I get IE to return the background
color in rgb
format, or how do I convert the text color to its rgb value? Thanks!


Here's a link that may help
http://web.njit.edu/~kevin/rgb.txt.html
HTH
Hal
May 19 '06 #2
Thanks, but I don't want to hardcode the rgb values in my code. I was
hoping for some attribute I could access or parameter I could pass to
an existing method that would return the current background color as an
rgb value rather than as the color name.

May 21 '06 #3

te*****@ucia.go v wrote:
Thanks, but I don't want to hardcode the rgb values in my code. I was
hoping for some attribute I could access or parameter I could pass to
an existing method that would return the current background color as an
rgb value rather than as the color name.


I haven't tried it, but you could look at
http://www.phpied.com/rgb-color-parser-in-javascript/

May 21 '06 #4

<te*****@ucia.g ov> schreef in bericht
news:11******** **************@ y43g2000cwc.goo glegroups.com.. .
We've got some JavaScript code that gets the current background color.
It works, but Netscape returns it in rgb format, while IE returns it as
the color
text name (e.g., 'white'). We need to do some math calculations on the
color,
so I want the rgb values. How can I get IE to return the background
color in rgb
format, or how do I convert the text color to its rgb value? Thanks!


Only works for Internet Explorer!!!!!!! !!!

Create a table with it's visibility style set to hidden, set this tables
bgcolor
to the named color:
<table id="temptable" bgcolor="indigo "><tr><td></td></tr></table>

then request back the color:
document.getEle mentById("tempt able").bgColor

it should return a hex color...

full sample:

<html>
<head>
<style>
#temptable{visi bility:hidden}
</style>
<script>
var hexChars = "0123456789ABCD EF";
function Dec2Hex (Dec) {
// this function isn't used in this sample
var a = Dec % 16;
var b = (Dec - a)/16;
hex = "" + hexChars.charAt (b) + hexChars.charAt (a);
return hex;
}
function Hex2Dec(HexVal) {
HexVal = HexVal.toUpperC ase();
var DecVal = 0;
var temp = HexVal.substrin g(0,1);
DecVal = (hexChars.index Of(temp) * 16);
temp = HexVal.substrin g(1);
DecVal += hexChars.indexO f(temp);
return DecVal;
}

function test(){
var HexString = document.getEle mentById("tempt able").bgColor;
var r = Hex2Dec(HexStri ng.substring(1, 3));
var g = Hex2Dec(HexStri ng.substring(3, 5));
var b = Hex2Dec(HexStri ng.substring(5, 7));
alert("hex: " + HexString + "\nrgb: " + r + " " + g + " " + b);
}
</script>
</head>
<body onclick="test() ">

<table id="temptable" bgcolor="indigo "><tr><td></td></tr></table>

</body>
</html>
May 21 '06 #5
Marc wrote on 21 mei 2006 in comp.lang.javas cript:
function Hex2Dec(HexVal) {
HexVal = HexVal.toUpperC ase();
var DecVal = 0;
var temp = HexVal.substrin g(0,1);
DecVal = (hexChars.index Of(temp) * 16);
temp = HexVal.substrin g(1);
DecVal += hexChars.indexO f(temp);
return DecVal;
}


function Hex2Dec(x){
var y = 0, z;
for(var i=0;i<x.length; i++){
z = x.toUpperCase() .charCodeAt(i)
y = 16*y+z-((z<58)?48:55)
}
return y;
}

[works for any length hex string within reason, even empty string]

=============== ===

function colorhex2dec(x) {
return x.replace(/(..)/g,function($1){ return Hex2Dec($1)+' '})
}

alert(colorhex2 dec('abcd10')) // 171 205 16

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 21 '06 #6
<knip>

function Hex2Dec(x){
var y = 0, z;
for(var i=0;i<x.length; i++){
z = x.toUpperCase() .charCodeAt(i)
y = 16*y+z-((z<58)?48:55)
}
return y;
}

[works for any length hex string within reason, even empty string]

=============== ===

function colorhex2dec(x) {
return x.replace(/(..)/g,function($1){ return Hex2Dec($1)+' '})
}

alert(colorhex2 dec('abcd10')) // 171 205 16


Ah! nice... ;-)
May 22 '06 #7
Marc wrote on 22 mei 2006 in comp.lang.javas cript:
<knip>


Going Dutch?

Chello.nl?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
May 22 '06 #8
>> <knip>

Going Dutch?

Chello.nl?

yeps... but now at work ;-)
May 22 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
12938
by: Neal | last post by:
According to the CSS lint at http://htmlhelp.org/tools/csscheck/, "The shorthand background property is more widely supported than background-color." Can anyone point me to, or provide, information on what browsers have difficulty with the non-shortcut methods of setting background properties?
27
13574
by: Kevin Yu | last post by:
When I declare on HTML page <LINK href="mycss.css" type="text/css" rel=stylesheet /> .... <BODY class=myclass> in mycss.css BODY { FONT-WEIGHT: bold; FONT-SIZE: 12px; FONT-FAMILY: Arial, Geneva; background-image: url(images/back.jpg); }
0
1478
by: Bell, Kevin | last post by:
Does anyone know of a way to change the background color of the PythonWin windows from the blinding white, to another color, like the way MS Word will allow a dark blue background with white text? I know you can specify colors for all the different style of text via View/Options/Format, but I see nothing for the window itself. Kevin Bell
3
8821
by: Roberto Castro | last post by:
Hello! I have been assigned for the first time an adp Access project and so far I have managed to make the changes needed for some requirements. However, I am struggling to find the place where the application changes the color of the background of a textbox. Here the explanation goes: This is a form bound to an SQL view. The detail section has several fields, one of them being a textbox of name "Type". I checked its
2
8515
by: Tom van Stiphout | last post by:
Hi All, Access 2003. I would like to indicate required fields with a special background color. Easy for parent forms, but I also have several subforms in datasheet view. For those, I would like to color the vertical column in the special background color. The Infragistics grid control can do that for my VB6 applications. Am I correct in assuming Access can't do this?
3
3199
by: bulwark_jrm | last post by:
I'm trying to duplicate functionality found in a Windows application at one of my clients. Essentially, another programmer was able to arrange a lot of search options into a single dialog box by positioning the descriptive label behind the textbox instead of beside it. When the user enters text, the label disappears and the user types in their information into the textbox. I've figured out how to arrange a label behind the textbox...
0
2509
by: Thanu | last post by:
Hi, I want to import the background color of cells from excelsheet to Mshflexgrid in Vb6. I already have the code to import the contents from excel to mshflexgrid but i want to import the color also. And the text in some of the cells of mshflexgrid are not Fully visible.only half of the word is visible.How do i format the cells so that i get the entire text in that cell to be seen by stretching the cell size. please let me know as soon...
19
3982
by: david.karr | last post by:
If in my CSS I set the "background-color" property on the "body" element, it only covers the background of the elements defined in the body, up to the current width and height of the page. However, if the current component set has a resulting small height, this leaves most of the page with the original background color (white). However, if I set the property on the "html" element instead, it does color the entire visible page, beyond the...
0
8692
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9145
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7897
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5935
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4705
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2495
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2084
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.