2 min read
The window.navigator object contains information about the visitor’s browser.
window.navigator
The window.navigator object can be written without the window prefix.
Some examples:
navigator.appName
navigator.appCodeName
navigator.platform
The cookieEnabled property returns true if cookies are enabled, otherwise false:
cookieEnabled
<p id="demo"></p> <script> document.getElementById("demo").innerHTML = "cookiesEnabled is " + navigator.cookieEnabled; </script>
The appName property returns the application name of the browser:
appName
<p id="demo"></p> <script> document.getElementById("demo").innerHTML = "navigator.appName is " + navigator.appName; </script>
The appCodeName property returns the application code name of the browser:
appCodeName
<p id="demo"></p> <script> document.getElementById("demo").innerHTML = "navigator.appCodeName is " + navigator.appCodeName; </script>
“Mozilla” is the application code name for both Chrome, Firefox, IE, Safari, and Opera.
The product property returns the product name of the browser engine:
product
p id="demo"></p> <script> document.getElementById("demo").innerHTML = "navigator.product is " + navigator.product; </script>
Do not rely on this. Most browsers returns “Gecko” as product name !!
The appVersion property returns version information about the browser:
appVersion
<p id="demo"></p> <script> document.getElementById("demo").innerHTML = navigator.appVersion; </script>
The userAgent property returns the user-agent header sent by the browser to the server:
userAgent
<p id="demo"></p> <script> document.getElementById("demo").innerHTML = navigator.userAgent; </script>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.
The information from the navigator object can often be misleading, and should not be used to detect browser versions because:
The platform property returns the browser platform (operating system):
platform
<p id="demo"></p> <script> document.getElementById("demo").innerHTML = navigator.platform; </script>
The language property returns the browser’s language:
language
<p id="demo"></p> <script> document.getElementById("demo").innerHTML = navigator.language; </script>
The onLine property returns true if the browser is online:
onLine
<p id="demo"></p> <script> document.getElementById("demo").innerHTML = navigator.onLine; </script>
The javaEnabled() method returns true if Java is enabled:
javaEnabled()
<p id="demo"></p> <script> document.getElementById("demo").innerHTML = navigator.javaEnabled(); </script>
Powered by BetterDocs
You must be logged in to post a comment.