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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Piotr K

    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.getEle mentById("inner ").style.backgr oundColor =
    GetStyle("box", "backgroundColo r");
    document.getEle mentById("box") .style.backgrou ndColor = "transparen t";

    <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.
  • Henry

    #2
    Re: Opera and dynamic style change.. this must be a joke..

    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.getEle mentById("inner ").style.backgr oundColor =
    GetStyle("box", "backgroundColo r");
    document.getEle mentById("box") .style.backgrou ndColor = "transparen t";
    >
    <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.

    Comment

    • pr

      #3
      Re: Opera and dynamic style change.. this must be a joke..

      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.getEle mentById("inner ").style.backgr oundColor =
      GetStyle("box", "backgroundColo r");
      What is GetStyle()?
      document.getEle mentById("box") .style.backgrou ndColor = "transparen t";
      >
      <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.

      Comment

      • Piotr K

        #4
        Re: Opera and dynamic style change.. this must be a joke..

        On 22 Kwi, 12:21, pr <p...@porl.glob alnet.co.ukwrot e:
        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.getEle mentById("inner ").style.backgr oundColor =
        GetStyle("box", "backgroundColo r");
        >
        What is GetStyle()?
        >
        document.getEle mentById("box") .style.backgrou ndColor = "transparen t";
        >
        <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.getEle mentById(obj);

        if(style == "opacity") return GetOpacity(obj) ;

        if(obj.currentS tyle) return obj.currentStyl e[style];
        else if(window.getCo mputedStyle) return getComputedStyl e(obj,
        "").getProperty Value(style.rep lace(/[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", "backgroundColo r") == "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.

        Comment

        • VK

          #5
          Re: Opera and dynamic style change.. this must be a joke..

          On Apr 22, 3:52 am, Piotr K <piotr.korzenie w...@gmail.comw rote:
          document.getEle mentById("box") .style.backgrou ndColor = "transparen t";
          "transparen t" is an imaginary value. It was used in W3C docs to
          describe an element that has no color property set, like "transparen t
          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.getEle mentById('box') .style.backgrou ndColor = '';

          Comment

          • pr

            #6
            Re: Opera and dynamic style change.. this must be a joke..

            Piotr K wrote:
            Here's the GetStyle code:
            >
            function GetStyle(obj, style) {
            obj = document.getEle mentById(obj);
            >
            if(style == "opacity") return GetOpacity(obj) ;
            >
            if(obj.currentS tyle) return obj.currentStyl e[style];
            else if(window.getCo mputedStyle) return getComputedStyl e(obj,
            "").getProperty Value(style.rep lace(/[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", "backgroundColo r") == "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.backgroun dColor. Try this, for example:

            alert("*" + GetStyle("box", "backgroundColo r") + "*");

            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.

            Comment

            • Piotr K

              #7
              Re: Opera and dynamic style change.. this must be a joke..

              On 22 Kwi, 18:21, pr <p...@porl.glob alnet.co.ukwrot e:
              Piotr K wrote:
              Here's the GetStyle code:
              >
              function GetStyle(obj, style) {
              obj = document.getEle mentById(obj);
              >
              if(style == "opacity") return GetOpacity(obj) ;
              >
              if(obj.currentS tyle) return obj.currentStyl e[style];
              else if(window.getCo mputedStyle) return getComputedStyl e(obj,
              "").getProperty Value(style.rep lace(/[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", "backgroundColo r") == "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.backgroun dColor. Try this, for example:
              >
              alert("*" + GetStyle("box", "backgroundColo r") + "*");
              >
              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!

              Comment

              • Thomas 'PointedEars' Lahn

                #8
                Re: Opera and dynamic style change.. this must be a joke..

                VK wrote:
                On Apr 22, 3:52 am, Piotr K <piotr.korzenie w...@gmail.comw rote:
                >document.getEl ementById("box" ).style.backgro undColor = "transparen t";
                >
                "transparen t" is an imaginary value. It was used in W3C docs to describe
                an element that has no color property set, like "transparen t element",
                but it was not meant to be an actual string to assign to the style.
                Wrong on all accounts, see





                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.g etElementsByTag Name("*")[0];
                if (elemRef && typeof elemRef.style != "undefined" )
                {
                elemRef.style.b ackgroundColor = "red";
                window.alert("N ow it should have a red background.");
                elemRef.style.b ackgroundColor = "transparen t";
                window.alert("N ow 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.b ackgroundColor) are in fact supported by W3C DOM
                Level 2 CSS and _not_ a (fully) proprietary feature as I thought before.


                PointedEars
                --
                var bugRiddenCrashP ronePieceOfJunk = (
                navigator.userA gent.indexOf('M SIE 5') != -1
                && navigator.userA gent.indexOf('M ac') != -1
                ) // Plone, register_functi on.js:16

                Comment

                • VK

                  #9
                  Re: Opera and dynamic style change.. this must be a joke..

                  On Apr 22, 10:52 pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
                  wrote: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.g etElementsByTag Name("*")[0];
                  if (elemRef && typeof elemRef.style != "undefined" )
                  {
                  elemRef.style.b ackgroundColor = "red";
                  window.alert("N ow it should have a red background.");
                  elemRef.style.b ackgroundColor = "transparen t";
                  window.alert("N ow 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.b ackgroundColor) 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 :-)

                  Comment

                  • Thomas 'PointedEars' Lahn

                    #10
                    Re: Opera and dynamic style change.. this must be a joke..

                    VK wrote:
                    [...] Thomas 'PointedEars' Lahn [...] wrote:>
                    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.g etElementsByTag Name("*")[0];
                    > if (elemRef && typeof elemRef.style != "undefined" )
                    > {
                    > elemRef.style.b ackgroundColor = "red";
                    > window.alert("N ow it should have a red background.");
                    > elemRef.style.b ackgroundColor = "transparen t";
                    > window.alert("N ow 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.b ackgroundColor) 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/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>

                    Comment

                    Working...