 |
Web-safe color codes include the following RGB values:
0x00
0x33
0x66
0x99
0xCC
0xFF
The following JavaScript generates a table for displaying the websafe colors:
<script type="text/javascript"> <!--//--><![CDATA[//><!-- // Color code table
c = new Array('00', '33', '66', '99', 'cc', 'ff');
// Start color table
t = '<table border="1" cellpadding="6" style="border-collapse:collapse;">';
// Iterate red color
for (r = 0; r < 6; r++)
{
// Iterate green color
for (g = 0; g < 6; g++)
{
// Start color table row
t += '<tr>';
// Iterate blue color
for (b = 0; b < 6; b++)
{
// Get RGB (background) color code
L = '#' + c[r] + c[g] + c[b];
// Get alternative/tooltip text
A = L + ' = RGB('
+ parseInt('0x' + c[r]) + ', '
+ parseInt('0x' + c[g]) + ', '
+ parseInt('0x' + c[b]) + ')'
;
// Get "inverted" RGB (foreground) color code
F = '#' + c[5 - r] + c[5 - g] + c[5 - b];
// Color table cell
t += '<td align="center"'
+ ' style="'
+ 'background-color:' + L + ';'
+ 'color:' + F + ';'
+ 'font-family:Courier New;'
+ 'cursor:hand;'
+ '"'
+ ' title="' + A + '"'
+ ' onclick="alert(\'' + A + '\');"'
+ ' onmouseover="window.status=\'' + A + '\';"'
+ ' onmouseout="window.status=\' \';"'
+ '>' + L + '</td>'
;
}
// End color table row
t += '</tr>';
}
}
// Display color table
document.write(t + '</table>');
//--><!]]> </script>
Output/Display
JavaScript Application: Display Web-safe Colors • © 2025 Manfred Baumeister • Updated: 29 October 2008, 14:15:01 GMT
|