Best books about Javasript
|
Sometines
when we write Javascript, we need color in #RRGGBB format. But we
can not gurantee color input is in #RRGGBB format. For example, Red,
rgb(255,0,0), #333 etc are all legal color format. Some color value
input like 333333 without #. Or, any string value could be input
as color. How could we convert these colors to #RRGGBB format?
How
to do it?
You need the following Javascript to convert color to #RRGGBB format
function
parseColor(vValue) {
var oColorParser = document.createElement("body");
oColorParser.bgColor = vValue;
return oColorParser.bgColor;
}
|
Of course, we can not expect the above function coould do every
convert correctly. Only the kind of color like Red and 333333 could
be converted into #RRGGBB correctly, for the other input, different
browser could give different results.
|