473,387 Members | 1,532 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,387 software developers and data experts.

Opera and dynamic style change.. this must be a joke..

Ok, I tried simply everything that came to my mind and now I ran out
of ideas, but to the point - take a look at the code below

// GetStyle returns given style value (works fine)
document.getElementById("inner").style.backgroundC olor =
GetStyle("box", "backgroundColor");
document.getElementById("box").style.backgroundCol or = "transparent";

<div id="box" style="width: 100px; height: 100px; background-color:
Red">
<div id="inner" style="width: 50px; height: 50px"></div>
</div>

What this code do - it retrieves "background-color" style from "box"
element, assigns it to "inner" and then "box" background gets
transparent. Now the funny part - it works in every browser, except
Opera, where both elements gets transparent background. What's even
more funny, when I replace GetStyle(...) with string "Red" it works
fine (GetStyle also returns string). Can someone explain me what is
going on? It's so illogical that I'm starting to think that maybe this
is a bug in Opera..

Thanks for any help,
P.
Jun 27 '08 #1
9 1260
On Apr 22, 12:52 am, Piotr K wrote:
Ok, I tried simply everything that came to my mind and now I ran
out of ideas, but to the point - take a look at the code below

// GetStyle returns given style value (works fine)
document.getElementById("inner").style.backgroundC olor =
GetStyle("box", "backgroundColor");
document.getElementById("box").style.backgroundCol or = "transparent";

<div id="box" style="width: 100px; height: 100px; background-color:
Red">
<div id="inner" style="width: 50px; height: 50px"></div>
</div>

What this code do - it retrieves "background-color" style
from "box" element, assigns it to "inner" and then "box"
background gets transparent. Now the funny part - it works
in every browser, except Opera, where both elements gets
transparent background. What's even more funny, when I
replace GetStyle(...) with string "Red" it works fine
(GetStyle also returns string). Can someone explain
me what is going on? It's so illogical that I'm starting
to think that maybe this is a bug in Opera..

Thanks for any help,
I don't know what help you expect. You have not included the code
necessary for anyone else to even attempt to reproduce your symptoms,
let alone attribute cause and effect relationships to them. And no
matter how effective you assert your - GetStyle - function to be I bet
most would like to see the code in question and verify its suitability/
reliability for themselves.
Jun 27 '08 #2
pr
Piotr K wrote:
Ok, I tried simply everything that came to my mind and now I ran out
of ideas, but to the point - take a look at the code below

// GetStyle returns given style value (works fine)
document.getElementById("inner").style.backgroundC olor =
GetStyle("box", "backgroundColor");
What is GetStyle()?
document.getElementById("box").style.backgroundCol or = "transparent";

<div id="box" style="width: 100px; height: 100px; background-color:
Red">
<div id="inner" style="width: 50px; height: 50px"></div>
</div>

What this code do - it retrieves "background-color" style from "box"
element, assigns it to "inner" and then "box" background gets
transparent. Now the funny part - it works in every browser, except
Opera, where both elements gets transparent background. What's even
more funny, when I replace GetStyle(...) with string "Red" it works
fine (GetStyle also returns string). Can someone explain me what is
going on? It's so illogical that I'm starting to think that maybe this
is a bug in Opera..
Maybe it is, maybe it isn't. Post the code for GetStyle() and we might
be able to tell.
Jun 27 '08 #3
On 22 Kwi, 12:21, pr <p...@porl.globalnet.co.ukwrote:
Piotr K wrote:
Ok, I tried simply everything that came to my mind and now I ran out
of ideas, but to the point - take a look at the code below
// GetStyle returns given style value (works fine)
document.getElementById("inner").style.backgroundC olor =
GetStyle("box", "backgroundColor");

What is GetStyle()?
document.getElementById("box").style.backgroundCol or = "transparent";
<div id="box" style="width: 100px; height: 100px; background-color:
Red">
<div id="inner" style="width: 50px; height: 50px"></div>
</div>
What this code do - it retrieves "background-color" style from "box"
element, assigns it to "inner" and then "box" background gets
transparent. Now the funny part - it works in every browser, except
Opera, where both elements gets transparent background. What's even
more funny, when I replace GetStyle(...) with string "Red" it works
fine (GetStyle also returns string). Can someone explain me what is
going on? It's so illogical that I'm starting to think that maybe this
is a bug in Opera..

Maybe it is, maybe it isn't. Post the code for GetStyle() and we might
be able to tell.
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"

When I use GetStyle, the background gets transparent under Opera, but
if I replace it with simply "Red" string everything works fine. I
thought there may be some kind of referencing going on under Opera,
but I tried even copying each character from GetStyle return value to
array and than joining it into completely new string - still the same
effect.
Jun 27 '08 #4
VK
On Apr 22, 3:52 am, Piotr K <piotr.korzeniew...@gmail.comwrote:
document.getElementById("box").style.backgroundCol or = "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. Now it is supported by some newer browsers due to misreading
some badly written W3C samples. Neither Opera not IE6 are one of them.

Never Ever In Your Life :-) put style rules to their default values by
any explicit assignment: because you never in your life can guess what
explicit assignment is expected by some particular UA (think of the
infamous table element display glitch). Always use empty string
instead: this way any UA will restore what it needs by itself.

document.getElementById('box').style.backgroundCol or = '';
Jun 27 '08 #5
pr
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.
Jun 27 '08 #6
On 22 Kwi, 18:21, pr <p...@porl.globalnet.co.ukwrote:
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!
Jun 27 '08 #7
VK wrote:
On Apr 22, 3:52 am, Piotr K <piotr.korzeniew...@gmail.comwrote:
>document.getElementById("box").style.backgroundCo lor = "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.htm...und-properties
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-58190037
http://www.w3.org/TR/DOM-Level-2-Sty...yleDeclaration
http://www.w3.org/TR/DOM-Level-2-Sty...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
Jun 27 '08 #8
VK
On Apr 22, 10:52 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Wrong on all accounts, see

http://www.w3.org/TR/CSS2/colors.htm...und-properties
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-58190037
http://www.w3.org/TR/DOM-Level-2-Sty...yleDeclaration
http://www.w3.org/TR/DOM-Level-2-Sty...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 :-)
Jun 27 '08 #9
VK wrote:
[...] Thomas 'PointedEars' Lahn [...] wrote:
>Wrong on all accounts, see

http://www.w3.org/TR/CSS2/colors.htm...und-properties
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-58190037
http://www.w3.org/TR/DOM-Level-2-Sty...yleDeclaration
http://www.w3.org/TR/DOM-Level-2-Sty...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...l#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>
Jun 27 '08 #10

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

Similar topics

2
by: Csaba2000 | last post by:
How can I dynamically resize a button in Opera? The following code works for both IE 5.5 and NN 6.1, but Opera 7.01 is not budging. Any ideas? Thanks, Csaba Gabor from New York <!DOCTYPE...
13
by: TheKeith | last post by:
Is it just me or does opera and ie not render the float style properly? IE does a sucky job at it, but opera makes a total mess; Mozilla/Firefox renders it correctly however. I'm just trying to be...
2
by: Martin Doyle | last post by:
Ok, I'm building a JS-based limitless-sublevel dynamic menu and am making it cross browser as well - 3 packs of aspirin so far and counting ;) I'm having a weird rendering problem using Opera...
8
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I detect Opera/Netscape/IE? ----------------------------------------------------------------------- The...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.