jquerycssinternet-explorerbackground-colorsystemcolors

Getting system color from CSS using jQuery in IE


I have a css rule defining the background color as the window system color:

background-color: window;

When I try to get the background color using jQuery's css method: $(selector).css("background-color");. It works well in Google Chrome, it returns the correct color, albeit not as a system color, but translated to rgb(255,255,255). In IE9 it returns rgb(-1,-1,-1)... Which of course renders black and not white when applied.


Solution

  • May not be the "answer" you're looking for - but a couple of notes:

    As to "why this happens" - see http://msdn.microsoft.com/en-us/library/ie/aa358804(v=vs.85).aspx - particularly:

    Unlike the other named colors however, user-defined system colors have no numeric RGB equivalent because the exact color is not known until the Web page is viewed on the user's system.

    also note:

    The system color names have been deprecated in the Cascading Style Sheets, Level 3 (CSS3) recommendation.

    If it is an absolute requirement that you be able to determine the RGB color code of the user's system-color for window on IE then you could resort to https://developers.google.com/chrome/chrome-frame/ to bridge the gap