Briefly
The window
property returns an object describing the application (user agent) that runs the script. In the overwhelming majority of cases, this application is a browser. The object contains properties that describe the browser and methods for performing actions.
Frequently used properties:
user
returns a string that contains the name of the browser. You should not use this property to determine the user's browser! The specification recommends that browsers send minimal information in user
, and the value may change from version to version.
navigator.userAgent// 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:93.0) Gecko/20100101 Firefox/93.0'
navigator.userAgent // 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:93.0) Gecko/20100101 Firefox/93.0'
language
returns the preferred interface language in the form of a language tag. For example, en
, ru
, en
, etc. Usually, this is the language set in the browser settings.
languages
returns an array of preferred languages in order of preference. The first in the list will be the language returned by navigator
.
navigator.language// 'ru'navigator.languages// ['ru', 'en-US', 'es-ES']
navigator.language // 'ru' navigator.languages // ['ru', 'en-US', 'es-ES']
cookie
returns true
if the user's browser supports cookies and they are enabled, false
otherwise.
on
returns true
if the user has a network connection. Browsers attribute different meanings to the concept of "online," so this property is an unreliable source of data.
clipboard
is a convenient access to the clipboard from the Clipboard API. The object provides several methods for saving information to the clipboard and reading from it. write
is a universal method for saving data to the clipboard. You can use the special write
if you're sure that only text needs to be copied. Both methods are asynchronous and return a Promise
. To read from the clipboard, there are equivalent read
and read
.
The navigator
object contains many other properties, most of which are experimental or supported by specific browsers.
The methods of the navigator
object are used to interact with other WebAPIs. For example, the vibrate
method that triggers vibration on the user's device if it is supported: navigator