By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,635 Members | 1,707 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,635 IT Pros & Developers. It's quick & easy.

test for onscroll support

P: n/a
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]>

Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.
Jul 20 '05 #2

P: n/a
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


Jul 20 '05 #3

P: n/a
> 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

Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.