JavaScript Navigator Object

The Navigator object specifies information about client’s browser window such as version, mime type and plug-ins. The window.navigator is read only property which gives reference to navigator object which provides information about application running the script. There is no public standard that applies to the navigator object, but all major browsers support it.

JavaScript Navigator Object Syntax

navObj=window.navigator

JavaScript Navigator Object Properties

The following are the properties of Navigator object:

  • appName: It specifies name of the browser.
  • appCodeName: It returns code name of the browser.
  • appVersion: It returns version of the browser.
  • language: It indicates default language of the browser.
  • mimeTypes: it is used to return mime types supported by the browser.
  • platform: It indicates the platform in which browser is running.
  • plugins: It indicates plugins that are installed on the browser.
  • userAgent: It specifies user agent header.

Methods

The following are the methods of Navigator object:

  • javaEnabled: It indicates whether java is enabled or not. It returns boolean value.
  • taintEnabled: It indicates whether data taint is enabled or not.

JavaScript Navigator Object Example

<!DOCTYPE html>
<head>
<meta charset="ISO-8859-1">
<title>JavaScript Navigator</title>
</head>
<body>
	<script type="text/javascript">
		document.write(navigator.appName + "<br>");
		document.write(navigator.appCodeName + "<br>");
		document.write(navigator.appVersion + "<br>");
		document.write(navigator.cookieEnabled + "<br>");
		document.write(navigator.platform + "<br>");
		document.write(navigator.userAgent + "<br>");
	</script>
</body>
</html>
  • <script type=”text/javascript”> tag is used to define client side script which uses attribute type for specifying MIME type.
  • document.write(navigator.appName); line indicates name of the browser.
  • document.write(navigator.appCodeName); line indicates code name of the browser.
  • document.write(navigator.appVersion); line indicates version of the browser.
  • document.write(navigator.cookieEnabled); line indicates if cookies are enabled.
  • document.write(navigator.platform); line indicates the platform in which browser is running.
  • document.write(navigator.userAgent); line indicates user agent header.

JavaScript Navigator Object Demo

  • Save the file as JSnavigator_example.html in your system.
  • Just open the file in the browser, you will see the below picture in the browser.

When the execution process is completed successfully we will get the following output:

JavaScript Navigator Object

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind

*