473,395 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to modify the color according to background?

I have a function returning a string but the problem is that the
color of it is blue which suits me well for some pages but not for
others. Is it possible to "feel" what the color of the background
in the current document is and set the color of the output accordingly? The
background will be an image, in most cases.

--

Kindly
Konrad
---------------------------------------------------
May all spammers die an agonizing death; have no burial places;
their souls be chased by demons in Gehenna from one room to
another for all eternity and more.

Sleep - thing used by ineffective people
as a substitute for coffee

Ambition - a poor excuse for not having
enough sense to be lazy
---------------------------------------------------


Jul 23 '05 #1
11 3163
Konrad Den Ende wrote:
I have a function returning a string but the problem is that the
color of it is blue which suits me well for some pages but not for
others. Is it possible to "feel" what the color of the background
in the current document is and set the color of the output accordingly? The
background will be an image, in most cases.


<body onload="alert(getCurrentStyle());">
<script type="text/javascript">
function getCurrentStyle() {
if (document.defaultView && document.defaultView.getComputedStyle &&
document.body) {
var computedStyle = document.defaultView.getComputedStyle(document.bod y,
null);
return 'computedStyle = ' +
computedStyle.getPropertyValue('background-color');
} else if (document.body && document.body.currentStyle) {
return 'currentStyle = ' + document.body.currentStyle.backgroundColor;
} else if (document.bgColor) {
return 'bgColor = ' + document.bgColor;
}
}
</script>
</body>

If you run this in Opera 7.51 and Gecko-based browsers (Netscape 7, Mozilla,
Firefox, Camino), you get "transparent", unfortunately, in IE6SP1 and Netscape
4 you get "#ffffff".

Even if you set a background color using CSS: "body { background-color:Blue;
}" there are some differences. IE6SP1 shows "blue", however Gecko-based
browsers report "rgb(0, 0, 255)" and Opera 7.51 and Netscape 4.78 display
"#0000ff"

In other words, determining the background color of the page in a cross-browser
compatible way is not as simple as it first appears.

That said, I guess I have to ask why you would need to determine the background
color of the page at runtime. You are the one setting the background color on
the page, simply set a client-side variable to the color of the text you want
to use for that page. Better yet, use CSS and simply specify a different color
combination for different pages:

<style type="text/css">
body {
background-color: White;
color: Black;
}
span.specialColor {
color: Red;
}
</script>

or

<style type="text/css">
body {
background-color: Black;
color: White;
}
span.specialColor {
color: Blue;
}
</script>

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #2
JRS: In article <40***************@agricoreunited.com>, seen in
news:comp.lang.javascript, Grant Wagner <gw*****@agricoreunited.com>
posted at Tue, 22 Jun 2004 18:20:29 :

That said, I guess I have to ask why you would need to determine the background
color of the page at runtime. You are the one setting the background color on
the page, simply set a client-side variable to the color of the text you want
to use for that page.


It can be useful to know the reader's preferred background setting, in
order to be able to change foreground colour, maintaining background
preference and giving desired contrast.

If the setting has been read into a Number, it can then be XORed with
0xaabbcc, and if each of aa bb cc has either no bits or one bit set, the
new value will represent a colour with a known degree of difference from
the original.

Also, with CSS present, the page author may not find it easy to keep
track of the current background colour.

In general, if one can change a setting one should to be able to read it
first.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #3
Grant Wagner wrote:
Konrad Den Ende wrote:
I have a function returning a string but the problem is that the
color of it is blue which suits me well for some pages but not for
others. Is it possible to "feel" what the color of the background
in the current document is and set the color of the output
accordingly? The background will be an image, in most cases.


<body onload="alert(getCurrentStyle());">
<script type="text/javascript">
function getCurrentStyle() {
if (document.defaultView && document.defaultView.getComputedStyle &&
document.body) {
var computedStyle =
document.defaultView.getComputedStyle(document.bod y, null);
return 'computedStyle = ' +
computedStyle.getPropertyValue('background-color');
} else if (document.body && document.body.currentStyle) {
return 'currentStyle = ' +
document.body.currentStyle.backgroundColor; } else if
(document.bgColor) { return 'bgColor = ' + document.bgColor;
}
}
</script>
</body>

If you run this in Opera 7.51 and Gecko-based browsers (Netscape 7,
Mozilla, Firefox, Camino), you get "transparent", unfortunately, in
IE6SP1 and Netscape 4 you get "#ffffff".

Even if you set a background color using CSS: "body {
background-color:Blue; }" there are some differences. IE6SP1 shows
"blue", however Gecko-based browsers report "rgb(0, 0, 255)" and
Opera 7.51 and Netscape 4.78 display "#0000ff"

In other words, determining the background color of the page in a
cross-browser compatible way is not as simple as it first appears.

<snip>

Another line of attack using - document.defaultView.getComputedStyle -
is to get an object implementing the - CSSValue - interface using the
computed style object's - getPropertyCSSValue - method (not implemented
in Opera 7 but available on Mozilla/Gecko and Konqueror/Safari):-

var cs = document.defaultView.getComputedStyle(el, null);
var CSSValue = cs.getPropertyCSSValue('background-color');

The returned CSSValue object (may be null, check it is not null before
use) has a - cssValueType - numeric property that corresponds with one
of 4 defined constants:-

CSS_INHERIT == 0
CSS_PRIMITIVE_VALUE == 1
CSS_VALUE_LIST == 2
CSS_CUSTOM == 3

If the object is CSS_PRIMITIVE_VALUE type it also implements the -
CSSPrimitiveValue
- interface. The - CSSPrimitiveValue - interface has a numeric property
called - primitiveType - that corresponds with another set of specified
constants including:-

CSS_IDENT == 21
CSS_RGBCOLOR == 25

A background color should be one of these two types. If it is CSS_IDENT
the value is likely to be "transparent". If it is CSS_RGBCOLOR then a -
getRGBColorValue - method may be called on the object to retrieve an
instance of the - RGBColor - interface.

var RGBColor = CSSValue.getRGBColorValue();

- which has properties - red, green and blue - that each refer to
objects implementing - CSSPrimitiveValue -. In the case of these objects
the likely - primitiveType - values are:-

CSS_NUMBER == 1
CSS_PERCENTAGE == 2

With CSS_NUMBER being the type used on Mozilla. In the W3C CSS DOM
specification it says that it should be possible to retrieve the value
in either form, but Mozilla only allows the value to be acquired as a
CSS_NUMBER. Retrieving the value is done with the - getFloatValue -
method passing the type as its argument. CSS_NUMBER values are in the
range 0 to 255.

var redValue = RGBColor.red.getFloatValue(1);
var blueValue = RGBColor.blue.getFloatValue(1);
var greenValue = RGBColor.green.getFloatValue(1);

- but that might be implemented as:-

var type = RGBColor.red.primitiveType;
var redValue = RGBColor.red.getFloatValue(type)*((type == 2)?2.55:1);

- to allow for the possibility that the value may be a percentage
instead of a number in the range 0 to 255.

In principle the future should see these interfaces more widely
implemented and for the retrieval of color values they are probably
simpler to use than the examination of all of the permutations of string
values that might be available, followed by the extraction of the
contained color information.

Indeed I was recently forced to pursue these interfaces because it
turned out that Konqueror 3 has made the strange decision of returning,
for example, "border-right-width:4px" instead of "4px" from:-

cs.getPropertyValue('border-right-width');

- which means passing the result through - parseInt - returns NaN
instead of the width of the border in pixels.

I did some experiments to see what was available form computed style
objects on various browsers. The following are the functions I was using
for the task; passing the - getComputedCSSInfo - function an element
reference as its argument returns a string describing what information
is available form the computed style object, which can be written into a
textarea, for example:-

function getComputedCSSInfo(element){
var indent = '\n';
var temp,cs,defaultView,text = '';
if(element){
if(element.tagName){
text += '<'+element.tagName+'>\n';
}else if(element.nodeName){
text += 'Node Name == ['+element.nodeName+']\n';
}
if(element.nodeType){
text += 'Node Type == '+nodeType_names[element.nodeType]+'\n';
}
if(element.id){
text += 'ID == \"'+element.id+'\"\n';
}
if(element.className){
text += 'className == \"'+element.className+'\"\n';
}
if((defaultView = document.defaultView)&&
(defaultView.getComputedStyle) &&
(cs = defaultView.getComputedStyle(element, null))
){
for(var c = 0;c < CSSProprety_names.length;c++){
temp = cs.getPropertyValue(CSSProprety_names[c]);
if(typeof temp != 'undefined'){
text += indent + 'String value from - getPropertyValue(\''+
CSSProprety_names[c]+'\') == \"'+temp+'\"';
}
if( cs.getPropertyCSSValue){
temp = cs.getPropertyCSSValue(CSSProprety_names[c]);
if(temp){
text += indent +
'CSSValue object from - getPropertyCSSValue(\''+
CSSProprety_names[c]+'\') == ';
text += CSSValueReport(temp, (indent+'\t'));
}
}
if(typeof temp != 'undefined'){text += indent;}
}
}else if(element.currentStyle){
for(var c = 0;c < CSSStyleProperties_names.length;c++){
temp = element.currentStyle[CSSStyleProperties_names[c]];
if(typeof temp != 'undefined'){
text += indent +
'String value from - element.currentStyle.'+
CSSStyleProperties_names[c]+' == \"'+temp+'\"';
text += indent;
}
}
}
}
return text;
}

function CSSValueReport(cssValue, indent){
var type = cssValue.cssValueType;
var st = indent+'CSSValue Type == '+type+' -> '+
(CSSValueType_names[type]||'not a specified type');
switch(type){
case 0: //CSS_INHERIT
st += indent+'The value is inherited : data == '+
cssValue.cssText;
break;
case 1: //CSS_PRIMITIVE_VALUE
st += CSSPrimativeReport(cssValue, (indent+'\t'));
break;
case 2: //CSS_VALUE_LIST
for(var c = 0;c < cssValue.length;c++){
st += indent+'Item == '+c;
st += CSSValueReport(cssValue.item(c), (indent+'\t'));
}
break;
case 3: //CSS_CUSTOM
st += indent+'The value is a custom value : data == '+
cssValue.cssText;
break;
default:
break;
}
return st;
}
function CSSPrimativeReport(cssValue, indent){
var temp,type = cssValue.primitiveType;
var st = indent+'CSSPrimitiveValue Type == '+type+' -> '+
(CSSPrimativeType_names[type]||'not a specified type');
switch(type){
case 0: //CSS_UNKNOWN
st += indent+
'Value is not a recognized CSS2 value: data == '+
cssValue.cssText;
break;

case 18: //CSS_DIMENSION
case 1: //CSS_NUMBER
case 2: //CSS_PERCENTAGE
case 3: //CSS_EMS
case 4: //CSS_EXS
case 5: //CSS_PX
case 6: //CSS_CM
case 7: //CSS_MM
case 8: //CSS_IN
case 9: //CSS_PT
case 10: //CSS_PC
st += indent+'Float value is == '+
cssValue.getFloatValue(type);
st += tryLengthConversion(cssValue, (indent+'\t'));
break;

case 11: //CSS_DEG
case 12: //CSS_RAD
case 13: //CSS_GRAD
case 14: //CSS_MS
case 15: //CSS_S
case 16: //CSS_HZ
case 17: //CSS_KHZ
st += indent+'Float value is == '+
cssValue.getFloatValue(type);
st += tryOtherConversion(cssValue, (indent+'\t'));
break;

case 19: //CSS_STRING
case 20: //CSS_URI
case 21: //CSS_IDENT
case 22: //CSS_ATTR
st += indent+'String value is == \"'+
cssValue.getStringValue()+'\"';
break;

case 23: //CSS_COUNTER
temp = cssValue.getCounterValue();
st += indent+'Counter.identifier == '+temp.identifier;
st += indent+'Counter.listStyle == '+temp.listStyle;
st += indent+'Counter.separator == '+temp.separator;
break;

case 24: //CSS_RECT
temp = cssValue.getRectValue();
st += indent+'Rect.top == '+
CSSPrimativeReport(temp.top, (indent+'\t'));
st += indent+'Rect.left == '+
CSSPrimativeReport(temp.left, (indent+'\t'));
st += indent+'Rect.bottom == '+
CSSPrimativeReport(temp.bottom, (indent+'\t'));
st += indent+'Rect.rigth == '+
CSSPrimativeReport(temp.right, (indent+'\t'));
break;

case 25: //CSS_RGBCOLOR
temp = cssValue.getRGBColorValue();
st += indent+'RGBColor.red == '+
CSSPrimativeReport(temp.red, (indent+'\t'));
st += indent+'RGBColor.green == '+
CSSPrimativeReport(temp.green, (indent+'\t'));
st += indent+'RGBColor.blue == '+
CSSPrimativeReport(temp.blue, (indent+'\t'));
break;

default:
break;
}
return st;
}

function tryLengthConversion(cssValue, indent){
var temp,type = cssValue.primitiveType;
var st = indent+'Length Values -> ';
try{ //CSS_NUMBER
st += indent+'CSS_NUMBER value == '+cssValue.getFloatValue(1);
}catch(e){
st += indent+'Cannot Convert to CSS_NUMBER (exception)';
}
try{ //CSS_PERCENTAGE
st += indent+'CSS_PERCENTAGE value == '+
cssValue.getFloatValue(2);
}catch(e){
st += indent+'Cannot Convert to CSS_PERCENTAGE (exception)';
}
try{ //CSS_EMS
st += indent+'CSS_EMS value == '+ cssValue.getFloatValue(3);
}catch(e){
st += indent+'Cannot Convert to CSS_EMS (exception)';
}
try{ //CSS_EXS
st += indent+'CSS_EXS value == '+ cssValue.getFloatValue(4);
}catch(e){
st += indent+'Cannot Convert to CSS_EXS (exception)';
}
try{ //CSS_PX
st += indent+'CSS_PX value == '+ cssValue.getFloatValue(5);
}catch(e){
st += indent+'Cannot Convert to CSS_PX (exception)';
}
try{ //CSS_CM
st += indent+'CSS_CM value == '+ cssValue.getFloatValue(6);
}catch(e){
st += indent+'Cannot Convert to CSS_CM (exception)';
}
try{ //CSS_MM
st += indent+'CSS_MM value == '+ cssValue.getFloatValue(7);
}catch(e){
st += indent+'Cannot Convert to CSS_MM (exception)';
}
try{ //CSS_IN
st += indent+'CSS_IN value == '+ cssValue.getFloatValue(8);
}catch(e){
st += indent+'Cannot Convert to CSS_IN (exception)';
}
try{ //CSS_PT
st += indent+'CSS_PT value == '+ cssValue.getFloatValue(9);
}catch(e){
st += indent+'Cannot Convert to CSS_PT (exception)';
}
try{ //CSS_PC
st += indent+'CSS_PC value == '+ cssValue.getFloatValue(10);
}catch(e){
st += indent+'Cannot Convert to CSS_PC (exception)';
}
return st;
}

function tryOtherConversion(cssValue, indent){
var temp,type = cssValue.primitiveType;
var st = indent+'Values -> ';
try{ //CSS_DEG
st += indent+'CSS_DEG value == '+ cssValue.getFloatValue(11);
}catch(e){
st += indent+'Cannot Convert to CSS_DEG (exception)';
}
try{ //CSS_RAD
st += indent+'CSS_RAD value == '+ cssValue.getFloatValue(12);
}catch(e){
st += indent+'Cannot Convert to CSS_RAD (exception)';
}
try{ //CSS_GRAD
st += indent+'CSS_GRAD value == '+ cssValue.getFloatValue(13);
}catch(e){
st += indent+'Cannot Convert to CSS_GRAD (exception)';
}
try{ //CSS_MS
st += indent+'CSS_MS value == '+ cssValue.getFloatValue(14);
}catch(e){
st += indent+'Cannot Convert to CSS_MS (exception)';
}
try{ //CSS_S
st += indent+'CSS_S value == '+ cssValue.getFloatValue(15);
}catch(e){
st += indent+'Cannot Convert to CSS_S (exception)';
}
try{ //CSS_HZ
st += indent+'CSS_HZ value == '+ cssValue.getFloatValue(16);
}catch(e){
st += indent+'Cannot Convert to CSS_HZ (exception)';
}
try{ //CSS_KHZ
st += indent+'CSS_KHZ value == '+ cssValue.getFloatValue(17);
}catch(e){
st += indent+'Cannot Convert to CSS_KHZ (exception)';
}
return st;
}

var CSSValueType_names = ['CSS_INHERIT','CSS_PRIMITIVE_VALUE',
'CSS_VALUE_LIST','CSS_CUSTOM'];

var CSSPrimativeType_names = ['CSS_UNKNOWN','CSS_NUMBER',
'CSS_PERCENTAGE','CSS_EMS','CSS_EXS','CSS_PX','CSS _CM','CSS_MM',
'CSS_IN','CSS_PT','CSS_PC','CSS_DEG','CSS_RAD','CS S_GRAD',
'CSS_MS','CSS_S','CSS_HZ','CSS_KHZ','CSS_DIMENSION ','CSS_STRING',
'CSS_URI','CSS_IDENT','CSS_ATTR','CSS_COUNTER','CS S_RECT',
'CSS_RGBCOLOR'];

var CSSProprety_names = [
'azimuth','background','background-attachment','background-color',
'background-image','background-position','background-repeat',
'border','border-collapse','border-color','border-spacing',
'border-style','border-top','border-right','border-bottom',
'border-left','border-top-color','border-right-color',
'border-bottom-color','border-left-color','border-top-style',
'border-right-style','border-bottom-style','border-left-style',
'border-top-width','border-right-width','border-bottom-width',
'border-left-width','border-width','bottom','caption-side',
'clear','clip','color','content','counter-increment',
'counter-reset','cue','cue-after','cue-before','cursor',
'direction','display','elevation','empty-cells','float','font',
'font-family','font-size','font-size-adjust','font-stretch',
'font-style','font-variant','font-weight','height','left',
'letter-spacing','line-height','list-style','list-style-image',
'list-style-position','list-style-type','margin','margin-top',
'margin-right','margin-bottom','margin-left','marker-offset',
'marks','max-height','max-width','min-height','min-width',
'orphans','outline','outline-color','outline-style',
'outline-width','overflow','padding','padding-top',
'padding-right','padding-bottom','padding-left','page',
'page-break-after','page-break-before','page-break-inside',
'pause','pause-after','pause-before','pitch','pitch-range',
'play-during','position','quotes','richness','right','si ze',
'speak','speak-header','speak-numeral','speak-punctuation',
'speech-rate','stress','table-layout','text-align',
'text-decoration','text-indent','text-shadow','text-transform',
'top','unicode-bidi','vertical-align','visibility','voice-family',
'volume','white-space','widows','width','word-spacing','z-index'
];

var CSSStyleProperties_names = [
'azimuth','background','backgroundAttachment','bac kgroundColor',
'backgroundImage','backgroundPosition','background Repeat','border',
'borderCollapse','borderColor','borderSpacing','bo rderStyle',
'borderTop','borderRight','borderBottom','borderLe ft',
'borderTopColor','borderRightColor','borderBottomC olor',
'borderLeftColor','borderTopStyle','borderRightSty le',
'borderBottomStyle','borderLeftStyle','borderTopWi dth',
'borderRightWidth','borderBottomWidth','borderLeft Width',
'borderWidth','bottom','captionSide','clear','clip ',
'color','content','counterIncrement','counterReset ',
'cue','cueAfter','cueBefore','cursor','direction', 'display',
'elevation','emptyCells','cssFloat','font','fontFa mily',
'fontSize','fontSizeAdjust','fontStretch','fontSty le','fontVariant',
'fontWeight','height','left','letterSpacing','line Height',
'listStyle','listStyleImage','listStylePosition',' listStyleType',
'margin','marginTop','marginRight','marginBottom', 'marginLeft',
'markerOffset','marks','maxHeight','maxWidth','min Height',
'minWidth','orphans','outline','outlineColor','out lineStyle',
'outlineWidth','overflow','padding','paddingTop',' paddingRight',
'paddingBottom','paddingLeft','page','pageBreakAft er',
'pageBreakBefore','pageBreakInside','pause','pause After',
'pauseBefore','pitch','pitchRange','playDuring','p osition',
'quotes','richness','right','size','speak','speakH eader',
'speakNumeral','speakPunctuation','speechRate','st ress',
'tableLayout','textAlign','textDecoration','textIn dent',
'textShadow','textTransform','top','unicodeBidi',' verticalAlign',
'visibility','voiceFamily','volume','whiteSpace',' widows',
'width','wordSpacing','zIndex'
];

var nodeType_names = ['','ELEMENT_NODE','ATTRIBUTE_NODE','TEXT_NODE',
'CDATA_SECTION_NODE','ENTITY_REFERENCE_NODE','ENTI TY_NODE',
'PROCESSING_INSTRUCTION_NODE','COMMENT_NODE','DOCU MENT_NODE',
'DOCUMENT_TYPE_NODE','DOCUMENT_FRAGMENT_NODE','NOT ATION_NODE'];

Richard.
Jul 23 '05 #4
Richard Cornford wrote:
Another line of attack using - document.defaultView.getComputedStyle -
is to get an object implementing the - CSSValue - interface using the
computed style object's - getPropertyCSSValue - method (not implemented
in Opera 7 but available on Mozilla/Gecko and Konqueror/Safari):-

var cs = document.defaultView.getComputedStyle(el, null);


document.defaultView == window // true

in Gecko-based browsers.
PointedEars
Jul 23 '05 #5
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
Another line of attack using - document.defaultView.getComputedStyle -
is to get an object implementing the - CSSValue - interface using the
computed style object's - getPropertyCSSValue - method (not implemented
in Opera 7 but available on Mozilla/Gecko and Konqueror/Safari):-

var cs = document.defaultView.getComputedStyle(el, null);

document.defaultView == window // true

in Gecko-based browsers.


document.defaultView === window

is more definitive, wouldn't you think?
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 23 '05 #6
Randy Webb wrote:
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
Another line of attack using - document.defaultView.getComputedStyle -
is to get an object implementing the - CSSValue - interface using the
computed style object's - getPropertyCSSValue - method (not implemented
in Opera 7 but available on Mozilla/Gecko and Konqueror/Safari):-

var cs = document.defaultView.getComputedStyle(el, null);


document.defaultView == window // true

in Gecko-based browsers.


document.defaultView === window

is more definitive, wouldn't you think?


Not in this case, since we know that both operands are references.
Two references are equal if, and only if, they refer to the same
object. FWIW: Both boolean expressions evaluate to `true' in
Gecko-based browsers.
PointedEars
Jul 23 '05 #7
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
Another line of attack using - document.defaultView.getComputedStyle
- is to get an object implementing the - CSSValue - interface using
the computed style object's - getPropertyCSSValue - method (not
implemented in Opera 7 but available on Mozilla/Gecko and
Konqueror/Safari):-

var cs = document.defaultView.getComputedStyle(el, null);


document.defaultView == window // true

in Gecko-based browsers.


True but it is an implementation decision (followed by Opera and
Safari/Konqueror). The W3C specs don't require it (they still say
nothing about the global object) and - document.defaultView - in
IceBrowser 5 is an isolated object (though it does not implement -
getCoumputedStyle - (at least in version 5, version 6 has just been
released but I haven't had time to look yet)).

In principal any object could implement the relevant interface, and that
would not be a problem so long as the - document.defaultView - property
referred to it. I can understand why most browsers consider the -
window - to be the right object to be implementing that interface but I
don't intend coding the assumption that - document.defaultView ===
window - into any of my scripts.

Richard.
Jul 23 '05 #8
Richard Cornford wrote:
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
var cs = document.defaultView.getComputedStyle(el, null);
document.defaultView == window // true

in Gecko-based browsers.


True but it is an implementation decision (followed by Opera and
Safari/Konqueror). The W3C specs don't require it (they still say
nothing about the global object)


It is not the global object that getComputedStyle() is
a property of in the Gecko DOM, but Window objects.
and - document.defaultView - in IceBrowser 5 is an isolated object
-v
(though it does not implement - getCoumputedStyle - (at least in
version 5, version 6 has just been released but I haven't had time
to look yet)).
And thus it does not matter here.
In principal any object could implement the relevant interface, and that
would not be a problem so long as the - document.defaultView - property
referred to it. I can understand why most browsers consider the -
window - to be the right object to be implementing that interface but I
don't intend coding the assumption that - document.defaultView ===
window - into any of my scripts.


As long as `document' is considered a proprietary reference as well
as `window', this would not be a reasonable decision.

But it turns out that the AbstractView interface of DOM Level 2 Views
has a `document' attribute which implements a DocumentView interface
which in turn has a `defaultView' attribute which implements the
AbstractView interface. Since `document.defaultView == window' and
window has a `document' property in the Gecko DOM, that may be not
as proprietary as we thought so far because `window' could implement
the AbstractView interface which is quite sound for window-based Web
browsers.
PointedEars
Jul 23 '05 #9
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
var cs = document.defaultView.getComputedStyle(el, null);

document.defaultView == window // true

in Gecko-based browsers.
True but it is an implementation decision (followed by Opera and
Safari/Konqueror). The W3C specs don't require it (they still say
nothing about the global object)


It is not the global object that getComputedStyle() is
a property of in the Gecko DOM, but Window objects.


When web browsers universally implement the global object and the window
object as the same object there is no meaningful distinction (and the
W3C specs also have nothing to say about the window object anyway).
and - document.defaultView - in IceBrowser 5 is an isolated object


-v
(though it does not implement - getCoumputedStyle - (at least in
version 5, version 6 has just been released but I haven't had time
to look yet)).


And thus it does not matter here.


But If IceBrowser 6 has implemented a working- getComputedStyle - on
its - doecument.defaultView - object then it is complying with W3C CSS
standard (in addition to W3C Views) to exactly the same degree as
Mozilla, Opera and Safari.
In principal any object could implement the relevant interface, and
that would not be a problem so long as the - document.defaultView -
property referred to it. I can understand why most browsers consider
the - window - to be the right object to be implementing that
interface but I don't intend coding the assumption that -
document.defaultView === window - into any of my scripts.


As long as `document' is considered a proprietary reference as well
as `window', this would not be a reasonable decision.


It is a completely reasonable decision. While the W3C may not have said
that the global object has a - document - property that points to an
object implementing the Document, HTMLDocument and DocumentView
interfaces we know that once we get to that object we are in W3C
specified territory. If DocumentView is implemented that object has a
defaultView property and that property refers to an object implementing
AbstractView, and if CSS level 2 is supported that abstractView object
will implement - getCoumputedStyle -. The only non-specified step in
that process is assuming that a global - document - property is a
reference to such a document, and without that browser scripting is not
practical anyway. There is only one unspecified assumption in that
process and nobody has been able to cite a browser where that assumption
does not hold (at least a global - document - property always refers to
a document, though it is not always a W3C document on older browsers).

Assuming that the global/window object is the object implementing
AbstractView is following an unspecified relationship where at least one
(W3C DOM standard dynamic visual) browser has been cited as not making
that implementation decision.
But it turns out that the AbstractView interface of DOM Level 2 Views
has a `document' attribute which implements a DocumentView interface
which in turn has a `defaultView' attribute which implements the
AbstractView interface. Since `document.defaultView == window' and
document.defaultView == window - only on some browsers, it is an
implementation decision not a specified relationship.
window has a `document' property in the Gecko DOM, that may be not
as proprietary as we thought so far because `window' could implement
the AbstractView interface which is quite sound for window-based Web
browsers.


If the Gecko DOM implementation of the W3C specs was an *official*
reference implementation then you might have a case, but it is not and
IceBrowser 5.4's implementation of DOM Views is 100% in accordance with
the published specification.

Interoperable W3C DOM standard browser scripting is going to be most
effective when it follows the specifications not the Gecko DOM
implementation of those specifications (to the extent that it is
possible). In a system specified as interfaces and relationships between
interfaces there are many possible equally valid (though perhaps more or
less obvious) correct implementations.

Richard.
Jul 23 '05 #10
Richard Cornford wrote:
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
> var cs = document.defaultView.getComputedStyle(el, null);
document.defaultView == window // true

in Gecko-based browsers.

True but it is an implementation decision (followed by Opera and
Safari/Konqueror). The W3C specs don't require it (they still say
nothing about the global object)
It is not the global object that getComputedStyle() is a property
of in the Gecko DOM, but Window objects.


When web browsers universally implement the global object and the
window object as the same object there is no meaningful distinction
(and the W3C specs also have nothing to say about the window object
anyway).


s/When/If/

There is no `window' object. As of DOM Level 0 evolved since IE/NN 3,
there is a `window' property of the global object that refers to its
owner. There are Window objects which have this property in the Gecko DOM:

var w = window.open("", "foo");
alert(w.getComputedStyle);
and - document.defaultView - in IceBrowser 5 is an isolated
object


-v
This means: Please explain.
(though it does not implement - getCoumputedStyle - (at least in
version 5, version 6 has just been released but I haven't had
time to look yet)).


And thus it does not matter here.


But If IceBrowser 6 has implemented a working- getComputedStyle - on
its - doecument.defaultView - object then it is complying with W3C
CSS standard (in addition to W3C Views) to exactly the same degree as
Mozilla, Opera and Safari.


Has the global object or the object referred to by a built-in `window'
property of the global object, if there is any, a getComputedStyle
property that works this way?
In principal any object could implement the relevant interface,
and that would not be a problem so long as the -
document.defaultView - property referred to it. I can understand
why most browsers consider the - window - to be the right object
to be implementing that interface but I don't intend coding the
assumption that - document.defaultView === window - into any of
my scripts.


As long as `document' is considered a proprietary reference as well
as `window', this would not be a reasonable decision.


It is a completely reasonable decision.


It is not:
While the W3C may not have said that the global object has a -
document - property that points to an object implementing the
Document, HTMLDocument and DocumentView interfaces we know that once
we get to that object we are in W3C specified territory. [...]
Nonsense.
Assuming that the global/window object is the object implementing
AbstractView is following an unspecified relationship where at least
one (W3C DOM standard dynamic visual) browser has been cited as not
making that implementation decision.
Assuming that the `document' property of the global object is the object
implementing DocumentView is following an unspecified relationship, too.
where at least one (W3C DOM standard dynamic visual) browser has been
cited as not making that implementation decision.
You have not told about IceBrowser's global object and its properties.

Besides, I seems a bit strange to argue against proprietary referencing
and in favor of another proprietary referencing on the Web.
Nevertheless, IceBrowser ist just *one* browser you have named making
that decision. There are more Gecko-based browsers than one. *If* I
would follow your strange logic, would that not mean that the majority
wins the case, so it would be Gecko-based browsers (Mozilla, Firefox,
Netscape 6.2+, Camino, among others), which proprietary referencing
should be considered the default case?
But it turns out that the AbstractView interface of DOM Level 2
Views has a `document' attribute which implements a DocumentView
interface which in turn has a `defaultView' attribute which
implements the AbstractView interface. Since `document.defaultView ^^^^^^^^^^^^^^^^^^^^^^^^^^^ == window' and ^^^^^^^^^^^^^^ document.defaultView == window - only on some browsers, it is an
implementation decision not a specified relationship.


I referred to the Gecko DOM with the whole subordinate clause:
window has a `document' property in the Gecko DOM, that may be not ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ as proprietary as we thought so far because `window' could
implement the AbstractView interface which is quite sound for
window-based Web browsers.


If the Gecko DOM implementation of the W3C specs was an *official*
reference implementation then you might have a case, but it is not
and IceBrowser 5.4's implementation of DOM Views is 100% in
accordance with the published specification.


It would be 100% in accordance with the published specification if, and
only if, this specification would state that the global object has a
`document' property that implements the interface. Obviously, it is not.
PointedEars
Jul 23 '05 #11
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote:
Thomas 'PointedEars' Lahn wrote:
Richard Cornford wrote: <snip> and - document.defaultView - in IceBrowser 5 is an isolated
object

-v
This means: Please explain.
What is to explain? The - defaultView - property of the document object
refers to an object implementing the - AbstractView - interface 100% in
accordance with the W3C DOM Views specification, and that object is not
the global/window object.
(though it does not implement - getCoumputedStyle - (at least in
version 5, version 6 has just been released but I haven't had
time to look yet)).

And thus it does not matter here.


But If IceBrowser 6 has implemented a working- getComputedStyle - on
its - doecument.defaultView - object then it is complying with W3C
CSS standard (in addition to W3C Views) to exactly the same degree as
Mozilla, Opera and Safari.


Has the global object or the object referred to by a built-in `window'
property of the global object, if there is any,


They are the same object.
a getComputedStyle property that works this way?
I have not had a chance to examine IceBrowser 6 at all yet. But if it
does implement - getComputedStyle - it would make more sense for them to
place it on the object that implements - AbstractView - and is referred
to by the document's - defaultView - property, as is called for by the
DOM CSS specification, than to place it on some other object.
In principal any object could implement the relevant interface,
and that would not be a problem so long as the -
document.defaultView - property referred to it. I can understand
why most browsers consider the - window - to be the right object
to be implementing that interface but I don't intend coding the
assumption that - document.defaultView === window - into any of
my scripts.

As long as `document' is considered a proprietary reference as well
as `window', this would not be a reasonable decision.


It is a completely reasonable decision.


It is not:
While the W3C may not have said that the global object has a -
document - property that points to an object implementing the
Document, HTMLDocument and DocumentView interfaces we know that once
we get to that object we are in W3C specified territory. [...]


Nonsense.


Please explain. Indeed please stop barking 'nonsense' at people, if
there is a reason that something is nonsense say what it is. Your
assertion carries no weight on its own and much of your recent logic has
been very questionable.
Assuming that the global/window object is the object implementing
AbstractView is following an unspecified relationship where at least
one (W3C DOM standard dynamic visual) browser has been cited as not
making that implementation decision.


Assuming that the `document' property of the global object is the
object implementing DocumentView is following an unspecified
relationship, too.


It is. But an object that does implement - DocumentView - is specified
as having a - defaultView - property that refers to an object
implementing the - AbstractView - interface, and that cannot be said of
any other object.
where at least one (W3C DOM standard dynamic visual) browser has been
cited as not making that implementation decision.


You have not told about IceBrowser's global object and its properties.

Besides, I seems a bit strange to argue against proprietary
referencing and in favor of another proprietary referencing on the
Web.


The proprietary reference - document - does refer to a W3C DOM specified
object on W3C standard browsers. The W3C does not make any specification
about the global/window object at all. I am arguing that you should go
to the specified object by whatever means are available and then follow
the standards from there. You are proposing shortcoming to an object
that you are assuming is implementing a particular interface when you
have no better reason for believing that it does than the fact that
particular implementations have chosen to implement the W3C specs that
way.
Nevertheless, IceBrowser ist just *one* browser you have
named making that decision.
it is the only example that I am currently aware of. It does, however,
illustrate that since the W3C DOM Views specification does not require
the object implementing - AbstractView - that is referred to by -
defaultView - to be the global/window object, - defaulteView - should
not be assumed to refer to the global/window object.
There are more Gecko-based browsers than one. *If* I
would follow your strange logic, would that not mean that
the majority wins the case,
How does this represent my "strange logic"?
so it would be Gecko-based browsers (Mozilla, Firefox,
Netscape 6.2+, Camino, among others), which proprietary referencing
should be considered the default case?


There is no default case; there are published DOM standards that say
nothing about the global/window object but say a great deal about
document objects.

<snip>
If the Gecko DOM implementation of the W3C specs was an *official*
reference implementation then you might have a case, but it is not
and IceBrowser 5.4's implementation of DOM Views is 100% in
accordance with the published specification.


It would be 100% in accordance with the published specification if,
and only if, this specification would state that the global object
has a `document' property that implements the interface. Obviously,
it is not.


The IceBrowser 5.4 implementation of DOM Views is 100% in accordance
with the specification. Its document implements - DocumentView - and the
object referred to by the - defaultView - property implements -
AbstractView -, just as the specification calls for. The browser's
implementation of a global - document - property does not influence that
at all.

Richard.
Jul 23 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Markus Mohr | last post by:
Hi, everyone, I have a special problem: For every monitor resolution in 200 pixel steps from 800 to 1600 pixels I have an image to be shown as centered background-image. Those images all...
27
by: Kevin Yu | last post by:
When I declare on HTML page <LINK href="mycss.css" type="text/css" rel=stylesheet /> .... <BODY class=myclass> in mycss.css BODY { FONT-WEIGHT: bold; FONT-SIZE: 12px; FONT-FAMILY:...
3
by: Viken Karaguesian | last post by:
Hello all, Me again :>) Can I modify certain attributes in a style within a stylesheet? Example: I have a style sheet that looks like this: body { background-color: black; font-family: Arial;...
2
by: Ed Mullen | last post by:
Ok, I get the thing about specifying color and background-color together. So I specify: background-color: transparent; in my CSS file. And I still get the warning. The CSS file is: ...
14
by: Seige | last post by:
Ever had headache when you can't resize the background width using CSS: body{ background: url(/images/bg.jpg) ; background-width: 800px; } It won't work, would it? Of course not, it's not even...
7
by: Fabien LE LEZ | last post by:
Hello, I'd like to put, on a web page, a "place" where the user can type a rather long text, with automatic coloring of each word (e.g. a color depending on the number of letters of the word). ...
5
by: DavidB | last post by:
Greetings I don't know if this is possible, but this group should be able to tell me. I have a webpage with a changing message board (I understand the problems with having changing text, but...
19
by: deko | last post by:
Is it possible to modify the background-image for a certain web page with PHP? I'd like to but a few buttons on the top of a page so readers can select from 2 or 3 different background images (or...
2
by: patrick.waldo | last post by:
Hi all, I am trying to figure out a way to read colors with xlrd, but I did not understand the formatting.py module. Basically, I want to sort rows that are red or green. My initial attempt...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.