
Originally Posted by
AllanP
There are several problems to this approach. Unless you set the background colour yourself on loading the page the test will fail, even though you set the colour using css.
Try this small script with and without the line setting the colour on a div that has a white background set in your css style.
window.onload=function()
{ var elem=document.getElementById("myDiv")
elem.style.backgroundColor="#000000"; // comment this out and run again
alert(elem.style.backgroundColor)
}
Another problem is that even if you do set the colour, IE browsers will return #000000 for a black background-color and non-IE browsers will return RGB(0,0,0). This makes comparison difficult without browser sniffing.
Also, if you decide to use the rgb format for all browsers, IE returns rgb(0,0,0) on testing and some non-IE browsers return rgb(0, 0, 0). One is separated by spaces, the other is not.
You can solve the problem, but the script is a lot longer than you think!
Bookmarks