[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bgcolors on different platforms



Greetings!

I am writing with good news this evening for those using Javascript who have concerns 
about using background colours consistent across platforms.

I am authoring a site using a Macintosh and selected background, text and link colors 
based on the Mac's standard monitor gamma. When this site was viewed on a Windows 
machine the colors were somewhat different. One solution I came up with was to run a 
cgi-bin program to find the USER_AGENT thus determining the platform of the browser and 
linking to a page with the appropriate colour definition. This would have required two 
sets of code for every page.

This was an unacceptable solution for two reasons: (1) I cannot write cgi-bin scripts 
and (2) I was unwilling to write two sets of code for every page.

Therefore, I settled on some compromise colours. But, now thanks to Javascript, my 
concerns about cross-platform colour definitions are almost over.

The solution: Javascript can determine the USER_AGENT information, specifically, the 
platform of the browser, the name of the browser and version number. (No, you can't read 
the IP ... yet!)

So, now I'm going to include the following code at the beginning of everypage. I would 
much prefer to make a stationery document containing this code to define the colours and 
then add the rest of the code for the page than to make two sets of code for every page.

I am offering this code with no strings attached; feel free to use it, but please don't 
call it your own -- you don't need to give me public credit, just don't credit yourself 
for this. Thanks. If you use it, I would love just to get some e-mail telling me.


<script language="javascript">
var namer = navigator.userAgent
var start = namer.indexOf("(") + 1
var end = namer.indexOf(";")
var comp = namer.substring(start,end)

if (comp == "Macintosh") {
document.write("<body bgcolor=#000033 text=#ffffff>")
} else document.write("<body bgcolor=#000044 text=#ffffff>")

</script>


I found bgcolor=#000033 on the Mac's standard gamma to be roughly equivalent to 
bgcolor=#000044 for Windows. I haven't tested for other platforms, so I supose the 
script is incomplete, but it's a start.

I would like to build on this by finding out what the value of 'comp' would be on other 
platforms. If you find this out, please e-mail me. Thanks. (comp is a variable and can 
be displayed on the screen by document.write(comp) before the </script> tag.)

I have a short page which demonstrates this ability, but you will need to view it on 
different platforms to see the subtle differences. You may also be interested in copying 
the code for displaying the name of the browser and the platform name. This code can be 
used with the same request I make above.

The URL for this example is http://www.panix.com/~sdpalmer/javacolour.html

Best regards,
SETH

_________________________________________________________________
Seth D. Palmer                                     VISA LA FRANCE
sdpalmer@panix.com          - Don't leave your chateau without it.

                    DIGI.INTELLIGENTSIA, LTD.
           Technologies Avancees-Solutions Creatrices