The JavaScript navigator object is useful for customizing your JavaScript based on the user’s browser and what they have enabled on that browser. Remember all browsers are different and handle JavaScript differently. For example, the user might not have cookies enabled, but has JavaScript enabled. Let’s take a better look at what I am talking about through examples.
While I still express my rage for some browser incompatibility, it is much better than it used to be. This ultimately means that things like the navigator object are losing their importance. Back in the day, you would use the navigator object to structure you code. So, if the user was on internet explorer, use this code, but if they are on safari, use this code. The navigator is now more commonly used to track information about the user, which can also be attained by server-side programming languages adding to the lower importance of the navigator object.
Navigator Properties
- appCodeName – gets the code name of the browser
- appName – gets the name of the browser
- appVersion – gets the version
- cookieEnabled – tells us if cookies are enabled
- platform – gets the browsers platform
- userAgent – gets the header from the server request
I don’t usually deal with the navigator properties, unless I am setting JavaScript cookies or am gathering information about my user’s browsers. Last, but not least, I will show you the only useful method in the navigator class.
- javaEnabled() – tells us if Java is enabled