Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #13132
| Message-ID | <1793833.mheAe9J7Na@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2012-03-30 20:46 +0200 |
| Subject | Re: Browser Default Colors |
| Newsgroups | comp.lang.javascript |
| References | <q0l9n79p2tteamk95li9013sa1scbsothl@4ax.com> |
| Followup-To | comp.lang.javascript |
Followups directed to: comp.lang.javascript
Dr.Kral@nyc.rr.com wrote:
^^^^^^^^^^^^^^^^^^
It is of advantage if you post using your real name here.
> 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
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Browser Default Colors Dr.Kral@nyc.rr.com - 2012-03-29 17:30 -0400
Re: Browser Default Colors "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-30 06:50 +0000
Re: Browser Default Colors Dr.Kral@nyc.rr.com - 2012-03-30 14:08 -0400
Re: Browser Default Colors Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-03-30 20:59 +0200
Re: Browser Default Colors Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-03-30 20:46 +0200
Re: Browser Default Colors John G Harris <john@nospam.demon.co.uk> - 2012-03-31 11:49 +0100
Re: Browser Default Colors "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-31 11:49 +0000
Re: Browser Default Colors David Mark <dmark.cinsoft@gmail.com> - 2012-03-31 04:01 -0700
Re: Browser Default Colors Dr.Kral@nyc.rr.com - 2012-03-31 08:47 -0400
Re: Browser Default Colors David Mark <dmark.cinsoft@gmail.com> - 2012-03-29 18:22 -0700
csiph-web