Via Netscape's LiveConnect and Java, the operating system and its version can be detected, provided Java support is enabled. This script will report 'Windows 95-4.0-Pentium' for Netscape Navigator 3.03 32-bit for the PC we used to test with:
var str = ''; str += java.lang.System.getProperty('os.name'); str += java.lang.System.getProperty('os.version'); str += java.lang.System.getProperty('os.arch'); document.write(str);
This script works for Netscape 3.0 and 4.0 browsers.
A warning - watch out for the processor specific information in the above two example strings. 'I' and 'Pentium' may well vary if your computer doesn't have a genuine Pentium I processor, as most new computers don't now. It's safer to just test using the operating system version.
var str = ''; str += ' ' + ScriptEngineMajorVersion(); str += ' ' + ScriptEngineMinorVersion(); str += ' ' + ScriptEngineBuildVersion(); document.write(str);
Common output for this example would be '2 0 1125'.
Supporting Several Versions
The top.images property is problematic in some browsers, so calling change_image() won't always work. In this example, by testing the property against null, nothing is done if it doesn't exist. This allows feature-by-feature compatibility without regard to versions, but it also means using a lot of extra ifs if you use many non-portable features.
Which features should you watch out for? The Appendices extensively list the objects available, and specific well-known problems are discussed in the subject areas throughout this book where they are most often used - for example, read about images in the Multimedia and Plugins chapter.
Created: April 23, 2001
Revised: April 23, 2001