Das ist normal, dass der Browser das in der rgb()-Schreibweise speichert!
Hab mal schnell folgende Funktion geschrieben, was dir die Hex-Form (#) zurückgeben sollte:
Code:
function rgb2hex(str) {
// find all decimal color strings
var matcher = str.match(/rgb\([0-9 ]+,[0-9 ]+,[0-9 ]+\)/gi);
if(matcher) {
for(var j=0; j < matcher.length; j++) {
var regex = eval("/" + str2regex(matcher[j]) + "/gi");
// replace the decimal color strings with hex color strings
str = str.replace(regex, "#" + toHexColor(matcher[j]));
}
}
return str;
}
function str2regex(string) {
string = string.replace(/\//gi, "\\/");
string = string.replace(/\(/gi, "\\(");
string = string.replace(/\)/gi, "\\)");
string = string.replace(/\[/gi, "\\[");
string = string.replace(/\]/gi, "\\]");
string = string.replace(/\+/gi, "\\+");
string = string.replace(/\$/gi, "\\$");
string = string.replace(/\*/gi, "\\*");
string = string.replace(/\?/gi, "\\?");
string = string.replace(/\^/gi, "\\^");
string = string.replace(/\\b/gi, "\\\\b");
string = string.replace(/\\B/gi, "\\\\B");
string = string.replace(/\\d/gi, "\\\\d");
string = string.replace(/\\B/gi, "\\\\B");
string = string.replace(/\\D/gi, "\\\\D");
string = string.replace(/\\f/gi, "\\\\f");
string = string.replace(/\\n/gi, "\\\\n");
string = string.replace(/\\r/gi, "\\\\r");
string = string.replace(/\\t/gi, "\\\\t");
string = string.replace(/\\v/gi, "\\\\v");
string = string.replace(/\\s/gi, "\\\\s");
string = string.replace(/\\S/gi, "\\\\S");
string = string.replace(/\\w/gi, "\\\\w");
string = string.replace(/\\W/gi, "\\\\W");
return string;
}
function toHexColor(color) {
color = color.replace(/^rgb/g,'');
color = color.replace(/\(/g,'');
color = color.replace(/\)/g,'');
color = color.replace(/ /g,'');
color = color.split(',');
var r = parseFloat(color[0]).toString(16).toUpperCase();
var g = parseFloat(color[1]).toString(16).toUpperCase();
var b = parseFloat(color[2]).toString(16).toUpperCase();
if (r.length<2) { r='0'+r; }
if (g.length<2) { g='0'+g; }
if (b.length<2) { b='0'+b; }
return r + g + b;
}
Hoffe das es funktioniert, habs nicht wirklich getestet ^^