Don’t forget navigator.platform
navigator.userAgent. However, there are a number of properties on
navigator that are useful. One of the most useful is
navigator.platform returns a string representing the platform on which the browser is running. The platform is not the operating system per se, but rather the machine architecture. For Windows systems, the value is typically “Win32″ (I’d expect it to be “Win64″ for 64-bit systems, but I don’t have one to test on; it used to be “Win16″ on pre-Windows 95 systems); for Mac systems, it’s either “MacPPC” or “MacIntel” for Unix systems it’s typically “X11″ although Linux systems may have “Linux i686″. This information is useful in determining whether a browser is being used on a computer or a device.
On a hunch, I asked my co-worker Steve to hit a test page using his iPhone. As it turns out,
navigator.platform is “iPhone” (I’d expect it to be “iPod” for the iPod Touch). So that’s a very simple way, without user-agent string parsing, to determine that the browser is being used on the iPhone. I suspect (or rather hope) that devices such as the Wii and Playstation also change
navigator.platform to something logical. If anyone knows offhand, please let me know.
Another great thing about
navigator.platform is that it’s not spoofed, so its value can be relied upon. It can’t tell you explicitly about what browser is being used, but knowing the platform can be useful when cross-platform browser issues arise or for tracking purposes.
Disclaimer: Any viewpoints and opinions expressed in this article are those of Nicholas C. Zakas and do not, in any way, reflect those of my employer, my colleagues, Wrox Publishing, O'Reilly Publishing, or anyone else. I speak only for myself, not for them.
Both comments and pings are currently closed.