Click to See Complete Forum and Search --> : testing browser's capabilities


LittleRed
12-02-2003, 03:23 AM
hi

rather than having loads of tests for the user's browser before using later implemented script, is it valid to test directly for the property's existence and then use it?

say I want to use the availWidth property, could I use:

Var my_screen_width = 600;
if (document.screen.availWidth) {
my_screen_width = screen.availWidth;
}

then if the browser doesn't support the availWidth it will happily pass over the if section and the variable stays at the initialised value of 600?

thanks

Pittimann
12-02-2003, 03:56 AM
Hi!

I'm not really sure what you want.

Anyway, it is possible to test the property's existence and work with the result.
If you change your code to something like:

var my_screen_width = 600;
if (window.screen.availWidth) {
my_screen_width = window.screen.availWidth;
}

your variable my_screen_width will get the value of the availWidth if it exists. That is, what your condition checks.

Cheers - Pit

LittleRed
12-02-2003, 03:58 AM
thanks - that was pretty much what I wanted.

I just needed to make sure that if the property didn't exist it wouldn't cause any problems.

cheers