What is a navigator object in Javascript ?
Navigator object is used for browser detection.
By which we can get all the browser information.
How to access the navigator object ?
The navigator object is the window property,
So it can be accessed with or without the ‘window’ prefix.
Syntax :
window.navigator
or
navigator
What happens when we invoke navigator object ?
This object returns the actual browser information like appName,appVersion etc.
Javascript full tutorial !!!
Click to Learn More about – Javascript online learning
What are properties does navigator object return?
There are many properties returned by the navigator object listed below
1. appName
appName object returns the name
2. appVersion
appVersion object returns the version
3. appCodeName
appCodeName object returns the code name
4. cookieEnabled
cookieEnabled object returns true if cookie is enabled otherwise false
5. userAgent
userAgent object returns the user agent
6. language
Language object returns the language (It is supported only in Netscape and Firefox).
7. userLanguage
userLanguage object returns the user language (It is supported only in IE).
8. plugins
Plugins object returns the plugins (It is supported only in Netscape and Firefox).
9. systemLanguage
systemLanguage object returns the system language (It is supported only in IE).
10. mimeTypes[]
mimeTypes[] object returns the array of mime type (It is supported only in Netscape and Firefox).
11. platform
platform object returns the platform e.g. Win32.
12. online
Online object returns true if browser is online otherwise false.
1. With using ‘window’ object
Example :
<!DOCTYPE html>
<html>
<head>
<title>Our title</title>
<script type="text/javascript">
document.writeln("<br/>The navigator.appCodeName = "+window.navigator.appCodeName);
document.writeln("<br/>The navigator.appName = "+window.navigator.appName);
document.writeln("<br/>The navigator.appVersion = "+window.navigator.appVersion);
document.writeln("<br/>The navigator.cookieEnabled = "+window.navigator.cookieEnabled);
document.writeln("<br/>The navigator.language = "+window.navigator.language);
document.writeln("<br/>The navigator.userAgent = "+window.navigator.userAgent);
document.writeln("<br/>The navigator.platform = "+window.navigator.platform);
document.writeln("<br/>The navigator.onLine = "+window.navigator.onLine);
</script>
</head>
<body></body>
</html>
Output :
The navigator.appCodeName = Mozilla
The navigator.appName = Netscape
The navigator.appVersion = 5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36
The navigator.cookieEnabled = true
The navigator.language = en-GB
The navigator.userAgent = Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36
The navigator.platform = MacIntel
The navigator.onLine = true
2. Without using ‘window’ object
Example :
<!DOCTYPE html>
<html>
<head>
<title>Our title</title>
<script type="text/javascript">
document.writeln("<br/>The navigator.appCodeName = "+navigator.appCodeName);
document.writeln("<br/>The navigator.appName = "+navigator.appName);
document.writeln("<br/>The navigator.appVersion = "+navigator.appVersion);
document.writeln("<br/>The navigator.cookieEnabled = "+navigator.cookieEnabled);
document.writeln("<br/>The navigator.language = "+navigator.language);
document.writeln("<br/>The navigator.userAgent = "+navigator.userAgent);
document.writeln("<br/>The navigator.platform = "+navigator.platform);
document.writeln("<br/>The navigator.onLine = "+navigator.onLine);
</script>
</head>
<body></body>
</html>
But the output will be the same
Output :
The navigator.appCodeName = Mozilla
The navigator.appName = Netscape
The navigator.appVersion = 5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36
The navigator.cookieEnabled = true
The navigator.language = en-GB
The navigator.userAgent = Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36
The navigator.platform = MacIntel
The navigator.onLine = true
There are few methods in navigator object listed below,
Sno | Method / Function | Description |
1 | javaEnabled() | javaEnabled() method checks if java is enabled or not. |
2 | taintEnabled() | taintEnabled() method checks if taint is enabled or not.( this method is deprecated since JavaScript 1.2.) |