test for onscroll support

Discussion in 'Javascript' started by viza, Aug 26, 2003.

  1. viza

    viza Guest

    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.onscroll===undefined || some_other_stuff)
    do_something_else()
    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.onscroll) 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, Aug 26, 2003
    #1
    1. Advertising

  2. viza

    viza Guest

    and then Dom Leonard said:

    > viza wrote:
    >> Hi!

    >
    >>
    >> if(window.onscroll===undefined || some_other_stuff)
    >> do_something_else()
    >> 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.
    >>

    > 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.hasOwnProperty is,
    > well ummm, undefined) but I presume it has done something similar since
    > release of IE5.5. Note that although window.undefined 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_stuff)
    > 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.


    Thanks for the help. I think I have found another solution, using
    typeof(window.onscroll)=='undefined'. It works in IE6, but I havn't tested
    IE5 yet.

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


    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.
     
    viza, Aug 29, 2003
    #2
    1. Advertising

  3. viza

    Dom Leonard Guest

    Lasse Reichstein Nielsen wrote:

    >>Can't exactly test what IE6 has done (window.hasOwnProperty
    >>is undefined) but I presume it has done something similar
    >>since release of IE5.5.

    >
    >
    > Probably. In IE 6, the code
    > "undefined" in window
    > yields "true", so "undefined" is a property of the window object.
    >


    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.undefined property with attributes {dontEnum and dontDelete} to
    make up for the missing keyword.

    Internet Explorer 5.0 didn't implement window.undefined 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
     
    Dom Leonard, Aug 29, 2003
    #3
  4. > Historically Netscape failed to make "undefined" a javascript keyword,
    > which IHMO was a pity. In NS3, and perhaps earlier, it implemented a
    > window.undefined property with attributes {dontEnum and dontDelete} to
    > make up for the missing keyword.
    >
    > Internet Explorer 5.0 didn't implement window.undefined 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.


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

    typeof null == 'object'

    http://www.crockford.com/javascript/javascript.html
     
    Douglas Crockford, Aug 29, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    5,887
  2. Sam
    Replies:
    2
    Views:
    2,873
    IT Guy
    Sep 29, 2006
  3. Replies:
    0
    Views:
    684
  4. Replies:
    0
    Views:
    1,148
  5. Dan Phiffer

    onscroll artifacts on IE5/Mac

    Dan Phiffer, Jun 30, 2003, in forum: Javascript
    Replies:
    0
    Views:
    93
    Dan Phiffer
    Jun 30, 2003
Loading...

Share This Page