Can I detect older monitors and supply them with web-safe colours?

163 views Asked by At

I want to use non-web-safe colors in several places on my website, including for the background. But I am concerned about visitors with older computers.

Is there any code I can use that will change the color from the non-web-safe color to the nearest web-safe color if the visitor cannot see non-web-safe colors?

3

There are 3 answers

3
David Thomas On

As this question cannot, to my knowledge, be answered with simple HTML, I'm posting this JavaScript solution to offer an alternative means:

It's possible to use screen.colorDepth to return the color depth, in bits, of the user's screen. With the exception of a faulty/erroneous implementation in Firefox 3.x and 4.1 (beta).

var theImg = document.getElementsByTagName('img')[0];

if (screen.colorDepth < 32) {
    theImg.src = 'http://davidrhysthomas.co.uk/img/the_shat.png';
}
else {
    theImg.src = 'http://davidrhysthomas.co.uk/img/terry_thomas.png';
}

alert(screen.colorDepth);

Addenda with respect to PPK, Chromium 11/Ubuntu 11.04 also returns 24 rather than 32, so Firefox may have been correct.

JS Fiddle demo.

Reference:

0
Donnie H On

The browser will automatically do this if your using hex/color codes and not images. And with images they will just dither, graceful degrading their experience with no work.

http://www.limov.com/colour/when-to-use-the-web-safe-palette.lml

0
Richard Marskell - Drackir On

I may be mistaken here, but the point of web-safe colours was so that your images will look the same on a monitor with a lower colour depth (eg. 8-bit colour) as they would on one with a higher color depth (16/24-bit colour). Which would happen because all of those colours should (theoretically) be able to be displayed in all colour formats.

If you have an image that is not "web-safe", and you view it on a system with 8-bit colour, all of the colours that don't fit within the display's colour capabilities, should automatically be displayed as the closest colour that fits. Basically, you don't have to "convert" it. The bit depth of the colour doesn't allow it to display any OTHER colours and so it'll have to sub something in, which should be the next closest display colour.

That said, web-safe colours are from the time when displays only used 8-bit colour. I don't think that this is something you really have to worry about now unless you know that your audience is using very, very, old technology.