<!DOCTYPE> breaking a script?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matthew Schubert

    <!DOCTYPE> breaking a script?

    I have reason for an element on a page to be static, like the CSS property
    "position: fixed" defines.

    Obviously, this CSS property doesn't work in IE :-/

    I have looked around at alternatives, and found one that suits my needs, an
    active Javascript that changes the position of the element when the page is
    scrolled.

    A simple test implementation of the script can be seen at
    http://evil.mooo.com/test.html. It works perfectly.

    When I add a <!DOCTYPE> declaration to the top of the page, so it conforms
    with W3C's standards, the script breaks, and I get this
    http://evil.mooo.com/test2.html.

    What is happening? Any ideas?


  • ZER0

    #2
    Re: &lt;!DOCTYPE&gt ; breaking a script?

    On Mon, 04 Oct 2004 15:11:13 GMT, Matthew Schubert wrote:
    [color=blue]
    > I have reason for an element on a page to be static, like the CSS property
    > "position: fixed" defines.[/color]
    [color=blue]
    > Obviously, this CSS property doesn't work in IE :-/[/color]

    Exactly.
    [color=blue]
    > I have looked around at alternatives, and found one that suits my needs, an
    > active Javascript that changes the position of the element when the page is
    > scrolled.[/color]

    This is old school method. Use expression instead (IE5+)
    [color=blue]
    > When I add a <!DOCTYPE> declaration to the top of the page, so it conforms
    > with W3C's standards, the script breaks, and I get this
    > http://evil.mooo.com/test2.html.[/color]
    [color=blue]
    > What is happening? Any ideas?[/color]

    Replacing document.body with document.docume ntElement.

    You can check the document.compat Mode for choose body or documentElement .



    --
    ZER0://coder.gfxer.web-designer/

    ~ Come devo regolare la stampante laser per stordire?
    (How do I set a laser printer to stun?)

    on air ~ "Yellowcard - Breathing"

    Comment

    • Michael Winter

      #3
      Re: &lt;!DOCTYPE&gt ; breaking a script?

      On Mon, 04 Oct 2004 15:11:13 GMT, Matthew Schubert
      <sales@addstyle cleaning.com> wrote:
      [color=blue]
      > I have reason for an element on a page to be static, like the CSS
      > property "position: fixed" defines.
      >
      > Obviously, this CSS property doesn't work in IE :-/[/color]

      Someone asked for something similar recently in this thread:

      <URL:http://groups.google.c om/groups?threadm= 1319c3c8.040928 1107.1b34b642%4 0posting.google .com>

      Though in my final solution, the fixed content was centred. It's easy
      enough to adjust, though. Ask if you need help.
      [color=blue]
      > I have looked around at alternatives, and found one that suits my needs,
      > an active Javascript that changes the position of the element when the
      > page is scrolled.[/color]

      I must say, it's a horrible implementation. Browser detection should
      always be avoided with feature detection used in its place. In this case,
      I used Microsoft's conditional comments, the contents of which change the
      position property to absolute and add a script which moves the box when
      the page is scrolled.
      [color=blue]
      > A simple test implementation of the script can be seen at
      > http://evil.mooo.com/test.html. It works perfectly.
      >
      > When I add a <!DOCTYPE> declaration to the top of the page, so it
      > conforms with W3C's standards, the script breaks, and I get this
      > http://evil.mooo.com/test2.html.
      >
      > What is happening? Any ideas?[/color]

      The problem you're seeing is that when a DOCTYPE is specified, IE, like
      most browsers, switches into strict mode. When IE does this, it uses
      document.docume ntElement, not document.body, to hold the clientWidth, and
      similar, properties. The code I've presented adapts as necessary[1].

      Hope that helps,
      Mike


      [1] Many thanks to Richard Cornford for the concept, or at least an
      implementation of it.

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

      Comment

      • Matthew Schubert

        #4
        Re: &lt;!DOCTYPE&gt ; breaking a script?

        > This is old school method. Use expression instead (IE5+)

        Eh?
        [color=blue]
        > Replacing document.body with document.docume ntElement.[/color]

        Tried. Failed (At least in Firefox).


        Comment

        • ZER0

          #5
          Re: &lt;!DOCTYPE&gt ; breaking a script?

          On Mon, 04 Oct 2004 15:28:20 GMT, Matthew Schubert wrote:
          [color=blue][color=green]
          >> This is old school method. Use expression instead (IE5+)[/color][/color]
          [color=blue]
          > Eh?[/color]

          Learn with interactive lessons and technical documentation, earn professional development hours and certifications, and connect with the community.


          Of course, expressions are not a w3c standard. But fix a lot of stuff in
          IE.
          You can use position:fixed for the browsers w3c compliant; and expression
          for emulate it in IE.
          [color=blue][color=green]
          >> Replacing document.body with document.docume ntElement.[/color][/color]
          [color=blue]
          > Tried. Failed (At least in Firefox).[/color]

          I'm talking about IE. In IE it works. In Firefox it doesn't works 'cause
          you missed the "px" suffix in your measures.

          --
          ZER0://coder.gfxer.web-designer/

          ~ Io non soffro di pazzia, ne godo ogni minuto.
          (I don't suffer from insanity, I enjoy every minute of it)

          on air ~ "Donots - Saccharine Smiles"

          Comment

          • Matthew Schubert

            #6
            Re: &lt;!DOCTYPE&gt ; breaking a script?

            Why is the second <script> outside of the IE conditional comments?

            Is it not required only by IE in this case? (Remember I do not need the
            button to make the DIV visible).

            It is a nice implementation. One thing though. I do not like the way it
            "jerks" when scrolling. The original script I posted smoothly scrolled the
            DIV...

            Also, I tried replacing document.body with document.docume ntElement, and it
            works perfectly in IE, but not in Firefox :-/

            I think I will use your script, with a little modification :-) Thanks a
            bunch.


            Comment

            • Michael Winter

              #7
              Re: &lt;!DOCTYPE&gt ; breaking a script?

              On Mon, 04 Oct 2004 15:50:27 GMT, Matthew Schubert
              <sales@addstyle cleaning.com> wrote:
              [color=blue]
              > Why is the second <script> outside of the IE conditional comments?
              >
              > Is it not required only by IE in this case? (Remember I do not need the
              > button to make the DIV visible).[/color]

              The code there, part of a larger collection, is used in both the IE code
              and the showWait function, used to make the DIV appear.
              [color=blue]
              > It is a nice implementation. One thing though. I do not like the way it
              > "jerks" when scrolling. The original script I posted smoothly scrolled
              > the DIV...[/color]

              It was a quick fix. I woke up that morning and the first thing that came
              to my mind was: "If the user scrolls the page, the DIV will shift." Odd, I
              know. As I hadn't had anything back from the OP, I thought I should just
              add the extra code as soon as possible. I should have just tested though
              about it more in the first place.

              If you want smoother movement, I could add it if you want.
              [color=blue]
              > Also, I tried replacing document.body with document.docume ntElement, and
              > it works perfectly in IE, but not in Firefox :-/[/color]

              Firefox doesn't report properties like scrollTop on the HTML element
              (which is what documentElement refers to). However, as Firefox does
              support the fixed position value, there isn't much point in worrying about
              that.
              [color=blue]
              > I think I will use your script, with a little modification :-) Thanks a
              > bunch.[/color]

              You're welcome.

              Mike

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

              Comment

              • Duncan Booth

                #8
                Re: &lt;!DOCTYPE&gt ; breaking a script?

                Matthew Schubert wrote:
                [color=blue]
                > I have reason for an element on a page to be static, like the CSS
                > property "position: fixed" defines.
                >
                > Obviously, this CSS property doesn't work in IE :-/
                >
                > I have looked around at alternatives, and found one that suits my
                > needs, an active Javascript that changes the position of the element
                > when the page is scrolled.[/color]

                Have a look at IE7: http://dean.edwards.name/IE7/compatibility/fixed.html

                Comment

                • Mick White

                  #9
                  Re: &lt;!DOCTYPE&gt ; breaking a script?

                  Duncan Booth wrote:
                  [color=blue]
                  >
                  > Have a look at IE7: http://dean.edwards.name/IE7/compatibility/fixed.html[/color]



                  interesting source...

                  Mick

                  Comment

                  Working...