Click to See Complete Forum and Search --> : using document.all as browser detection


LittleRed
09-25-2003, 07:50 AM
is it valid to use the following to detect that the user's browser is either IE or Netscape?


if ((document.all || document.layers) {
...
}


thanks

Khalid Ali
09-25-2003, 08:29 AM
In general terms yes it will work,however,
document.all is too general statement,it will be true for all IE browsers,where as in IE6+ browsers there are differences of how toretrieve some values in JavaScript.
It can be good for Opera as well while you'd optimise your code only for IE<5.5.

document.layers is good for NS browsers <5 versions vers6+ can not be detected by that,for that you will need to get document.getElementById or/ and get the actual browsers version string and compare it

pyro
09-25-2003, 08:31 AM
If you just want to determine if it is IE or Netscape, why not use navigator.appName?

LittleRed
09-25-2003, 08:35 AM
I realised that I could use

navigator.appName == "Microsoft Internet Explorer"

to detect IE, but what's the definition for Netscape (does it return 'Mozilla'?)

pyro
09-25-2003, 08:40 AM
No, it returns "Netscape" via navigator.appName...

LittleRed
09-25-2003, 08:47 AM
ok ...it seemed to easy to be true!

pyro
09-25-2003, 08:49 AM
lol :D