|
Prev: FAQ Topic - Why does simple decimal arithmetic give strange results? (2008-04-22)
Next: XML and javascript
From: pr on 22 Apr 2008 12:21 Piotr K wrote: > Here's the GetStyle code: > > function GetStyle(obj, style) { > obj = document.getElementById(obj); > > if(style == "opacity") return GetOpacity(obj); > > if(obj.currentStyle) return obj.currentStyle[style]; > else if(window.getComputedStyle) return getComputedStyle(obj, > "").getPropertyValue(style.replace(/[A-Z]/g, function(obj, ch) {return > "-"+style.charAt(ch).toLowerCase()})); > } > > However I don't think this has anything to do with that strange > behaviour. In the example I posted earlier it returns simply "Red", so > in other words > > GetStyle("box", "backgroundColor") == "Red" Not quite. It appears in fact to return '"red"' - that is, a string containing double quote marks, which is not a sensible input for style.backgroundColor. Try this, for example: alert("*" + GetStyle("box", "backgroundColor") + "*"); Opera doesn't do it after the value has been set in code to 'transparent', so you may have to do a bit of research to find out when it occurs. My guess is when you use a named colour. A troublesome one to spot.
From: Piotr K on 22 Apr 2008 12:44 On 22 Kwi, 18:21, pr <p...(a)porl.globalnet.co.uk> wrote: > Piotr K wrote: > > Here's the GetStyle code: > > > function GetStyle(obj, style) { > > obj = document.getElementById(obj); > > > if(style == "opacity") return GetOpacity(obj); > > > if(obj.currentStyle) return obj.currentStyle[style]; > > else if(window.getComputedStyle) return getComputedStyle(obj, > > "").getPropertyValue(style.replace(/[A-Z]/g, function(obj, ch) {return > > "-"+style.charAt(ch).toLowerCase()})); > > } > > > However I don't think this has anything to do with that strange > > behaviour. In the example I posted earlier it returns simply "Red", so > > in other words > > > GetStyle("box", "backgroundColor") == "Red" > > Not quite. It appears in fact to return '"red"' - that is, a string > containing double quote marks, which is not a sensible input for > style.backgroundColor. Try this, for example: > > alert("*" + GetStyle("box", "backgroundColor") + "*"); > > Opera doesn't do it after the value has been set in code to > 'transparent', so you may have to do a bit of research to find out when > it occurs. My guess is when you use a named colour. > > A troublesome one to spot. You're absolutely right, all because of double quote marks returned by GetStyle, I can't believe I missed that, thank you sooo much - now everything works fine :) Thanks for all responses!
From: Thomas 'PointedEars' Lahn on 22 Apr 2008 14:52 VK wrote: > On Apr 22, 3:52 am, Piotr K <piotr.korzeniew...(a)gmail.com> wrote: >> document.getElementById("box").style.backgroundColor = "transparent"; > > "transparent" is an imaginary value. It was used in W3C docs to describe > an element that has no color property set, like "transparent element", > but it was not meant to be an actual string to assign to the style. Wrong on all accounts, see http://www.w3.org/TR/CSS2/colors.html#background-properties http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-58190037 http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSS2Properties > Now it is supported by some newer browsers due to misreading some badly > written W3C samples. Neither Opera not IE6 are one of them. Or maybe, just *maybe*, you are simply completely wrong *again* because both user agents do support that string value. I guess it does not bother you to be corrected all the time because a simple test -- like var elemRef = document.body.getElementsByTagName("*")[0]; if (elemRef && typeof elemRef.style != "undefined") { elemRef.style.backgroundColor = "red"; window.alert("Now it should have a red background."); elemRef.style.backgroundColor = "transparent"; window.alert("Now it should have a transparent background."); } -- before making further wild assumptions would have sufficed. Nevertheless, your stating nonsense has been helpful this time as I could find out that the `style' property and the shorthand CSS properties (for example elemRef.style.backgroundColor) are in fact supported by W3C DOM Level 2 CSS and _not_ a (fully) proprietary feature as I thought before. PointedEars -- var bugRiddenCrashPronePieceOfJunk = ( navigator.userAgent.indexOf('MSIE 5') != -1 && navigator.userAgent.indexOf('Mac') != -1 ) // Plone, register_function.js:16
From: VK on 22 Apr 2008 16:21 On Apr 22, 10:52 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de> wrote: > Wrong on all accounts, see > > http://www.w3.org/TR/CSS2/colors.html#background-properties > http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-58190037 > http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration > http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSS2Properties Some day I will maybe understand how anything written on W3C may force to work it on browser X. Some day... > I guess it does not bother you to > be corrected all the time because a simple test -- like > > var elemRef = document.body.getElementsByTagName("*")[0]; > if (elemRef && typeof elemRef.style != "undefined") > { > elemRef.style.backgroundColor = "red"; > window.alert("Now it should have a red background."); > elemRef.style.backgroundColor = "transparent"; > window.alert("Now it should have a transparent background."); > } So it works now, even on IE6? Great. I still highly suggest never use direct assignments for rule reset: use "" instead. Nobody is obligated to follow this advise of course. > Nevertheless, your stating nonsense has been helpful this time as I could > find out that the `style' property and the shorthand CSS properties (for > example elemRef.style.backgroundColor) are in fact supported by W3C DOM > Level 2 CSS and _not_ a (fully) proprietary feature as I thought before. Since DOM 1 to be exact. But better later than never :-)
From: Thomas 'PointedEars' Lahn on 22 Apr 2008 16:57 VK wrote: > [...] Thomas 'PointedEars' Lahn [...] wrote: >> Wrong on all accounts, see >> >> http://www.w3.org/TR/CSS2/colors.html#background-properties >> http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-58190037 >> http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration >> http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSS2Properties > > Some day I will maybe understand how anything written on W3C may force > to work it on browser X. Some day... It is *implemented as specified*, Often Wrong. >> I guess it does not bother you to >> be corrected all the time because a simple test -- like >> >> var elemRef = document.body.getElementsByTagName("*")[0]; >> if (elemRef && typeof elemRef.style != "undefined") >> { >> elemRef.style.backgroundColor = "red"; >> window.alert("Now it should have a red background."); >> elemRef.style.backgroundColor = "transparent"; >> window.alert("Now it should have a transparent background."); >> } > > So it works now, even on IE6? Now? Even? It works with *all* IE versions that support the `style' property, so since version 4.0 (documented and tested). Your attempts to conceal your cluelessness are even more ridiculous than your clueless boasting itself is. > Great. I still highly suggest never use direct assignments for rule reset: > use "" instead. Nobody is obligated to follow this advise of course. I would hope so, because your advice does not present an equivalent solution at all. Assigning the empty string resets the style property to its initial value (which ISTM to be a proprietary feature, CMIIW), but the cascade may cause the computed value of the property to be a completely different one. >> Nevertheless, your stating nonsense has been helpful this time as I could >> find out that the `style' property and the shorthand CSS properties (for >> example elemRef.style.backgroundColor) are in fact supported by W3C DOM >> Level 2 CSS and _not_ a (fully) proprietary feature as I thought before. > > Since DOM 1 to be exact. But better later than never :-) Wrong again. W3C DOM Level 1 only reserved the `style' attribute of the HTMLElement interface for future use, and it did not include a section on CSS interfaces. Furthermore, W3C DOM Level 1 HTML is rendered (and marked) obsolete by DOM Level 2 HTML since quite a while. http://www.w3.org/TR/REC-DOM-Level-1/level-one-html.html#ID-011100101 http://www.w3.org/TR/DOM-Level-2-HTML/ ("Status of this document", "Note:") Someone like you who continuously fails to get the basic facts right should be *very* slow to boast. Probably someone has told you that before. PointedEars -- Use any version of Microsoft Frontpage to create your site. (This won't prevent people from viewing your source, but no one will want to steal it.) -- from <http://www.vortex-webdesign.com/help/hidesource.htm>
First
|
Prev
|
Pages: 1 2 Prev: FAQ Topic - Why does simple decimal arithmetic give strange results? (2008-04-22) Next: XML and javascript |