Home » Tutorials » JavaScript » Navigator Object

Navigator Object

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
Example
<script type="text/javascript">
    document.write(navigator.appCodeName + "<br>");
    document.write(navigator.appName + "<br>");
    document.write(navigator.appVersion + "<br>");
    document.write(navigator.cookieEnabled + "<br>");
    document.write(navigator.platform + "<br>");
    document.write(navigator.userAgent + "<br>");
</script>
Result
Mozilla
Netscape
5.0 (Windows)
true
Win32
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.3) Gecko/20100101 Firefox/10.0.3

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
Example
document.write(navigator.javaEnabled());
Result
true


Link/cite this page

If you use any of the content on this page in your own work, please use the code below to cite this page as the source of the content.

  • Stewart, Suzy. "Navigator Object". After Hours Programming. Accessed on January 20, 2022. https://www.afterhoursprogramming.com/tutorial/javascript/navigator-object/.

  • Stewart, Suzy. "Navigator Object". After Hours Programming, https://www.afterhoursprogramming.com/tutorial/javascript/navigator-object/. Accessed 20 January, 2022.

  • Stewart, Suzy. Navigator Object. After Hours Programming. Retrieved from https://www.afterhoursprogramming.com/tutorial/javascript/navigator-object/.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.