test for onscroll support

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

    #1

    test for onscroll support

    Hi!

    I use the onscroll event to make something like the CSS position:fixed; for
    MSIE.

    In MSIE/5.5, before a function is assigned to the event handler, it has the
    value null. In Opera, it is undefined, because Opera doesn't support this
    event.

    I use:

    if(window.onscr oll===undefined || some_other_stuf f)
    do_something_el se()
    else
    window.onscroll =myfunction

    to check if it will work. Now this works in MSIE/5.5 and Opera, but in
    MSIE/5.0, it seems that the keyword 'undefined' is itself not defined.

    ***
    How can I test for the presence of this event handler without causing an
    error mesage in MSIE/5.0 ?
    ***

    Obviously, just if(window.onscr oll) won't work because both undefined and
    null are boolean false.

    You can see this in action (or not) at:

    http://www.touchwoodfurniture.co.uk/

    This site is new, so any other comments are welcomed.

    The script is:

    http://www.touchwoodfurniture.co.uk/scripts/ie5_foot.js

    (The equiv. for other browsers is css2_foot.js)

    Thanks!


    Tom Vajzovic <webmaster@[the above domain]>

  • viza

    #2
    Re: test for onscroll support

    and then Dom Leonard said:
    [color=blue]
    > viza wrote:[color=green]
    >> Hi![/color]
    >[color=green]
    >>
    >> if(window.onscr oll===undefined || some_other_stuf f)
    >> do_something_el se()
    >> else
    >> window.onscroll =myfunction
    >>
    >> to check if it will work. Now this works in MSIE/5.5 and Opera, but in
    >> MSIE/5.0, it seems that the keyword 'undefined' is itself not defined.
    >>[/color]
    > Which is true - undefined is not a keyword, and is being treated as an
    > identifier for which there is no declaration. This *should* generate a
    > ReferenceType error when getting the value and does so under IE5.0.
    > However, Mozilla and Opera seem to have predefined a window property
    > named "undefined" with the primitive value 'undefined' to get around the
    > error. Can't exactly test what IE6 has done (window.hasOwnP roperty is,
    > well ummm, undefined) but I presume it has done something similar since
    > release of IE5.5. Note that although window.undefine d exists in the
    > browsers tested, there is nothing to stop you setting it to a value...
    >
    > You could try
    > var U; // undefined value
    > if( window.onscroll ===U || some_other_stuf f)
    > blah blah etc...
    >
    > or for IE and Opera check out (and this might be more readable)
    >
    > if( window.onscroll ===null)
    > window.onscroll =myfunction;
    >
    > since under both Opera and IE the onscroll property pre-exists with the
    > value null. Neither of these will work under Mozilla/Netscape however,
    > since window.onscroll does not exist prior to being set. Hopefully this
    > is not a problem since you appear to be using a different script for non
    > IE browsers.[/color]

    Thanks for the help. I think I have found another solution, using
    typeof(window.o nscroll)=='unde fined'. It works in IE6, but I havn't tested
    IE5 yet.
    [color=blue]
    > PS, checked out the site in Mozilla, the fixed headers are working fine.
    > On the contact page, the <legend> element is not wrapping to window or
    > textarea size on my monitor. You may wish to check out white-space
    > properties for LEGEND or LEGEND treatment under Mozilla. Cheers.[/color]

    I'm aware of this, I just havn't fixed it yet. It's a case of Moz and IE
    both disobeying the spec in exactly the same way! That's a turn out for
    the books.

    Thanks for the help.

    Comment

    • Dom Leonard

      #3
      Re: test for onscroll support

      Lasse Reichstein Nielsen wrote:
      [color=blue][color=green]
      >>Can't exactly test what IE6 has done (window.hasOwnP roperty
      >>is undefined) but I presume it has done something similar
      >>since release of IE5.5.[/color]
      >
      >
      > Probably. In IE 6, the code
      > "undefined" in window
      > yields "true", so "undefined" is a property of the window object.
      >[/color]

      Where "Probably" => (p=1) :)

      Thanks Lasse, there is no question I have not been using the "in"
      operator. Having resolved to take on ECMA 262 as night time reading to
      make up, I should post the results:

      Historically Netscape failed to make "undefined" a javascript keyword,
      which IHMO was a pity. In NS3, and perhaps earlier, it implemented a
      window.undefine d property with attributes {dontEnum and dontDelete} to
      make up for the missing keyword.

      Internet Explorer 5.0 didn't implement window.undefine d so was incompatible.

      ECMA 262 defines "undefined" as a global property in section 15.1.1.3.
      Internet Explorer (since 5.5 presumably) and other ECMA compliant
      browsers now match this standard legitamising Netscape practice. So
      there is no doubt a current ECMA compliant browser should have a
      non-enumerable window property "undefined" emulating an undefined
      keyword, with the drawback it can be overwritten.

      Dom




      Comment

      • Douglas Crockford

        #4
        Re: test for onscroll support

        > Historically Netscape failed to make "undefined" a javascript keyword,[color=blue]
        > which IHMO was a pity. In NS3, and perhaps earlier, it implemented a
        > window.undefine d property with attributes {dontEnum and dontDelete} to
        > make up for the missing keyword.
        >
        > Internet Explorer 5.0 didn't implement window.undefine d so was incompatible.
        >
        > ECMA 262 defines "undefined" as a global property in section 15.1.1.3.
        > Internet Explorer (since 5.5 presumably) and other ECMA compliant
        > browsers now match this standard legitamising Netscape practice. So
        > there is no doubt a current ECMA compliant browser should have a
        > non-enumerable window property "undefined" emulating an undefined
        > keyword, with the drawback it can be overwritten.[/color]

        Yup. There are a number of implementation errors in the early browsers that ECMA
        cemented into the standard. Another one is

        typeof null == 'object'



        Comment

        Working...