Desperate, need javascript to covert a number to a color.

B

Big Dave

I'm going insane!!!!!

I set a font color using documentDOTexecuteCommand("ForeColor").

That works, but now I'm trying to read the color in another method. I
used documentDOTqueryCommandValue("ForeColor"). This method just
returns a number, and I can't figure out what the numbers are. I know
they have something to do with a color, but without knowing what they
are, it's hard to find help on how to convert them to something I can
use (hex, rgb). Here are two examples:
(Green returns 32768, Blue returns 16711689)

So, does anybody a)know what these numbers are? b)know how to convert
them to something more useful, or c)know how to generate these numbers
from a System.Drawing.Color in c#?

NOTE: DOT is due to the "no code" error on devdex. I didn't think I'd
get away with the real dots. Thank you in advance for your help!
Big Dave
 
B

Big Dave

That's the one, my company uses only IE, so it shouldn't be a problem.
I've got that part working, it's the return value of those colors. I
can't find anything that explains what they are or how to convert them.
They aren't RGB or hex. I need to find out how to convert them to
something I can use.

Big Dave
 
R

RobG

Big said:
That's the one, my company uses only IE, so it shouldn't be a problem.
I've got that part working, it's the return value of those colors. I
can't find anything that explains what they are or how to convert them.
They aren't RGB or hex. I need to find out how to convert them to
something I can use.

Big Dave

If you read the following post[1], it will tell you how to use
getComputedStyle and getCurrentStyle to get an element's properties.
From memory, IE will return colours exactly as they are set. So if
they are set using 'red', 'blue', etc. then that is what will be returned.

Mapping from RGB to colour names might be more easily achieved in
Firefox or another Geko browser, as they always report RGB values no
matter how the colour is set. It would take maybe 10 minutes to get
something that goes through all the named colours and prints out their
RGB equivalents. Conversion to hex should then be (even more) trivial.


1.
<URL:http://groups.google.com/group/comp...ab?q=getcomputedstyle&rnum=1#56c34b393de436ab>
 
V

vdP

Big said:
That works, but now I'm trying to read the color in another method. I
used documentDOTqueryCommandValue("ForeColor"). This method just
returns a number, and I can't figure out what the numbers are. I know
they have something to do with a color, but without knowing what they
are, it's hard to find help on how to convert them to something I can
use (hex, rgb). Here are two examples:
(Green returns 32768, Blue returns 16711689)

Are you sure these aren't rgb-values ? In hex the numbers read "00 80
00" (green) and "FF 00 09" (blue). The rgb-values of green and blue as
defined for html are "#00 80 00" and "#00 00 FF". So it seems that these
numbers are in rgb-format with the order of the three colors reversed. I
don't know about the 09 in the blue value, could it be a typo ?

vdP
 
R

RobG

vdP said:
Are you sure these aren't rgb-values ? In hex the numbers read "00 80
00" (green) and "FF 00 09" (blue). The rgb-values of green and blue as
defined for html are "#00 80 00" and "#00 00 FF". So it seems that these
numbers are in rgb-format with the order of the three colors reversed. I
don't know about the 09 in the blue value, could it be a typo ?

I would have expected 'green' to be #00ff00, but that is 'lime'. The
official reference is here:

<URL:http://www.w3.org/TR/html4/types.html#type-color>


The CSS 2.1 (work in progress) reference is here (it has bigger colour
swatches):

<URL:http://www.w3.org/TR/CSS21/syndata.html#value-def-color>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top