Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <1793833.mheAe9J7Na@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Fri, 30 Mar 2012 20:46:53 +0200 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 8Bit Subject: Re: Browser Default Colors Newsgroups: comp.lang.javascript References: Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 85 NNTP-Posting-Date: 30 Mar 2012 20:46:53 CEST NNTP-Posting-Host: 25629483.newsspool3.arcor-online.net X-Trace: DXC=Deo`N_YU6=AAa;:RKVJ>LEMcF=Q^Z^V3H4Fo<]lROoRA8kF Browser Default Colors As this is Network News, the subject of the message is already provided by the Subject header field value. You do not have to and you should not repeat that value in the message body. This applies to several other message header fields as well. > I would like to get the default colors used by a browser using ECMAScript > from within the displayed page. > > The function > document.getElementById("xxx").style.backgroundColor > only reports the value set by inline styles or style sheets. The property would only yield the value as declared in a `style' attribute, if present, and it is evidently not a function. > The functions > elem=document.getElementById("xxx") > document.defaultView.getComputedStyle(elem, "").backgroundColor The proper (standards-compliant) property access is document.defaultView.getComputedStyle(elem, null).backgroundColor or document.defaultView.getComputedStyle( elem, null).getPropertyValue("background-color") or document.defaultView.getComputedStyle( elem, null).getPropertyCSSValue("background-color") whereas the second one should return a primitive value and the third one a reference to an object (or `null'). > and > document.getElementById("xxx").currentStyle.backgroundColor There is also document.getElementById("xxx").runtimeStyle.backgroundColor in the MSHTML DOM. > do better and provide the actual rendered color value -- most of the time. In which instances have you observed which one to not provide it? > The value reported for the body and link backgrounds are given as > transparent or rgba(0,0,0,0) as the display shows the default background > color from the browser definitions. Is there a way to go one level > deeper? No, you are at the deepest level accessible to script authors already. If you disable all your author stylesheets (using the `disabled' property of objects implementing the StyleSheet interface), those are most of the time the values that are either the browser defaults or declared in a user stylesheet overriding the defaults. Keep in mind that the `body' element is not the root element of the document, so the default background color might be provided by the root element instead. However, authors should declare the background color of the `body' element, unless they go with the default text color. So one wonders what you think you will be needing this for. > While I'm asking, I'll also ask about the link colors. If one check a > displayed link element one does get unvisited color reliably but browsers > (for security reasons) may lie about the visited color. Correct. (Your *question* being?) PointedEars -- > If you get a bunch of authors […] that state the same "best practices" > in any programming language, then you can bet who is wrong or right... Not with javascript. Nonsense propagates like wildfire in this field. -- Richard Cornford, comp.lang.javascript, 2011-11-14