window.navigator for the current browser window.
Navigator Object Properties
The properties of the navigator object are the variables created inside the Navigator Object.
We can access Navigator Object Property as: navigator.propertyname where propertyname is the name of property.
|appcodename||specifies the code name of the browser (experimental property - can return incorrect value)|
|appname||specifies the name of the browser (experimental property - can return incorrect value)|
|appversion||specifies the version of browser being used (experimental property - can return incorrect value)|
|cookieEnabled||specifies whether cookies are enabled or not in the browser|
|platform||contains a string indicating the machine type for which the browser was compiled.|
|useragent||contains a string representing the value of user-agent header sent by the client to server in HTTP protocol|
|geolocation||returns object of GeoLocation which can be used to get the location information of the device.|
|onLine||specifies whether the browser is online or not.|
|language||returns a string with the preferred browser language, for example, en-US for English.|
|languages||returns a string with all the languages supported by the browser in order of user preference.|
There are some more expreimental properties available in the Navigator object, but the ones mentioned above are most commonly used properties.
Let's see a code example with some of these properties in action.
Navigator Object Methods
The Navigator object doesn't have many standardised methods, most of the methods available are experimental.
||allows websites to register themselves as protocol handler so that they are allowed to open some standard URL schemes like mailto:, tel:, sms:, etc,|
||used to utilize the native support of sharing available in browser.|
||used to send a small data packet from the client to the server|
||if supported, this can be used to make the device vibrate, if not supported, nothing happens. This is useful in mobile browsers.|
Use of Navigator Object:
The navigator object can be used for multiple specific usecases which can help you make your website better, like:
Making you web app or website more compatible with different browsers by writing specific code for different browsers to resolve compatibility issues.
You can check if the browser is online or not, to show some message if the browser is disconnected from internet.
You can use the location information of the user to show location specific content.
You can set the preferred language as the website language if you support multiple languages on your website.
All the points mentioned above can improve the user experience of your website multifold.