UCENwebster
Programmer
does anybody have a good way to switch NS6-7 colors from the format "rgb(R,G,B)" to a hex value like "#rrggbb"?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
function toHex(dec)
{
hexChars = "0123456789ABCDEF";
if (dec > 255)
{
return null;
}
var i = dec % 16;
var j = (dec - i) / 16;
result = hexChars.charAt(j);
result += hexChars.charAt(i);
return result;
}
function convertRGB2Hex(rgb)
{
var hexColor = "#";
rgb = rgb.substring(rgb.indexOf("(")+1,rgb.indexOf(")"));
rgb = rgb.split(",");
for (i=0;i<rgb.length;i++)
{
hexColor += toHex(rgb[i]);
}
return hexColor;
}
var ns = (navigator.appName == "Netscape") ? true : false;
var rules = (ns==true) ? "cssRules" : "rules";
var colorCode = eval("document.styleSheets[0]." + rules + "[0].style.color");
if (colorCode.indexOf("(") > -1)
{
colorCode = convertRGB2Hex(colorCode);
}