style property IE vs Netscape

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shawn Modersohn

    style property IE vs Netscape

    <script type="text/javascript">
    var browser=navigat or.appName
    if (browswer="Micr osoft Internet Explorer")
    document.styleS heets[0].rules[4].style.left="50 px"
    </script>

    IE does exactely what I hoped this script would do. Netscape says that
    document.styleS heets[0].rules has no properties. Since this script is
    targeted at IE anyway, should I be concerned? Also, is this script way
    oversimplified? All the css rule does is shift an image slightly to
    compensate for css overflow differences in the two browsers.

  • Lasse Reichstein Nielsen

    #2
    Re: style property IE vs Netscape

    Shawn Modersohn <smmodersohn@ho tmail.com> writes:
    [color=blue]
    > <script type="text/javascript">
    > var browser=navigat or.appName
    > if (browswer="Micr osoft Internet Explorer")[/color]

    Using "appName" to detect the browser is not reliable.
    I am using Opera. If I set it to emulate IE, it would also have
    an appName of "Microsoft Internet Explorer".
    [color=blue]
    > document.styleS heets[0].rules[4].style.left="50 px"[/color]
    [color=blue]
    > IE does exactely what I hoped this script would do. Netscape says
    > that document.styleS heets[0].rules has no properties.[/color]

    That's because it doesn't. Mozilla (and therefore Netscape 6+)
    implements the W3C DOM 2 Style specification, so it would be
    document.styleS heets[0].CSSrules
    [color=blue]
    > Since this script is targeted at IE anyway, should I be concerned?[/color]

    It gives an error where there is no need for it.
    [color=blue]
    > Also, is this script way oversimplified? All the css rule does is
    > shift an image slightly to compensate for css overflow differences
    > in the two browsers.[/color]

    Then it's not oversimplified, but overcomplicated .
    Just use IE's conditional comments:
    ---
    <!--[if lt IE 7]>
    <style type='text/css'>
    .someImeage { left : 50px; }
    </style>
    <![endif]-->
    ---

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Michael Winter

      #3
      [minor] Re: style property IE vs Netscape

      On Sun, 15 Aug 2004 12:35:40 +0200, Lasse Reichstein Nielsen
      <lrn@hotpop.com > wrote:

      [snip]
      [color=blue]
      > document.styleS heets[0].CSSrules[/color]

      cssRules

      [snip]

      Mike

      --
      Michael Winter
      Replace ".invalid" with ".uk" to reply by e-mail

      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: [minor] Re: style property IE vs Netscape

        "Michael Winter" <M.Winter@bluey onder.co.invali d> writes:
        [color=blue]
        > On Sun, 15 Aug 2004 12:35:40 +0200, Lasse Reichstein Nielsen
        > <lrn@hotpop.com > wrote:[/color]
        [color=blue][color=green]
        >> document.styleS heets[0].CSSrules[/color][/color]
        [color=blue]
        > cssRules[/color]

        Doh! Thanks.
        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • Brian

          #5
          Re: style property IE vs Netscape

          Shawn Modersohn wrote:
          [color=blue]
          > All the css rule does is shift an image slightly to compensate for
          > css overflow differences in the two browsers.[/color]

          Then why involve js at all?



          I don't know which one you need to hide it from. To use different widths
          for IE5 and Moz, use this:

          div.foo { width: 100%; } /* for MSIE 5.x win */
          html>body dif.foo { width: auto; } /* for Moz, Opera, and others */

          You'll have to adjust it to your needs. In general, it's best to use css
          parsing bugs to overcome css rendering bugs, just as it's best to use js
          object detection to avoid js errors.

          --
          Brian (remove ".invalid" to email me)

          Comment

          • Randy Webb

            #6
            Re: style property IE vs Netscape

            Shawn Modersohn wrote:[color=blue]
            > <script type="text/javascript">
            > var browser=navigat or.appName
            > if (browswer="Micr osoft Internet Explorer")
            > document.styleS heets[0].rules[4].style.left="50 px"
            > </script>
            >
            > IE does exactely what I hoped this script would do.[/color]

            Actually, it doesn't do what you *think* it does though.
            [color=blue]
            > Netscape says that document.styleS heets[0].rules has no properties.[/color]

            Thats because its taking the branch of the if that it shouldn't be,
            because you are doing an incorrect comparison. == is comparison, = is
            assignment. So your if statement is testing to see if it can set the
            string browser equal to "Microsoft Internet Explorer", which any browser
            should do and pass the test.

            The correct test would be (notwithstandin g the problems mentioned in
            other posts about the appName):

            if (browser == '...'){


            --
            Randy
            comp.lang.javas cript FAQ - http://jibbering.com/faq

            Comment

            • Alberto

              #7
              Re: style property IE vs Netscape

              Rearrange the expression
              document.styleS heets[0].rules[4].style.left="50 px"
              into:

              if(document.sty leSheets){
              document.styleS heets[0][
              (document.style Sheets[0].rules)?"rules" :"cssRules"
              ][4].style.left="50 px";
              };


              This grants a level of compatibility without browser sniffing.

              PS if by chance you add a style sheet node before that style sheet [0], or a
              css rule before rule [4], you won't arguably get anymore what you expect: if
              you're going to use that indexing, be sure the structure of your style
              sheets in your page never changes BEFORE index 4 of the rule, nor before
              index 0 of the style sheet itself.

              ciao
              Alberto







              "Shawn Modersohn" <smmodersohn@ho tmail.com> ha scritto nel messaggio
              news:4RGTc.853$ xW3.26@newssvr2 3.news.prodigy. com...[color=blue]
              > <script type="text/javascript">
              > var browser=navigat or.appName
              > if (browswer="Micr osoft Internet Explorer")
              > document.styleS heets[0].rules[4].style.left="50 px"
              > </script>
              >
              > IE does exactely what I hoped this script would do. Netscape says that
              > document.styleS heets[0].rules has no properties. Since this script is
              > targeted at IE anyway, should I be concerned? Also, is this script way
              > oversimplified? All the css rule does is shift an image slightly to
              > compensate for css overflow differences in the two browsers.
              >[/color]


              Comment

              Working...