Navigator - Web APIs 编辑

The Navigator interface represents the state and the identity of the user agent. It allows scripts to query it and to register themselves to carry on some activities.

A Navigator object can be retrieved using the read-only window.navigator property.

Properties

Doesn't inherit any properties, but implements those defined in NavigatorID, NavigatorLanguage, NavigatorOnLine, NavigatorContentUtils, NavigatorStorage, NavigatorStorageUtils, NavigatorConcurrentHardware, NavigatorPlugins, and NavigatorUserMedia.

Standard properties

Navigator.connection Read only This is an experimental API that should not be used in production code.
Provides a NetworkInformation object containing information about the network connection of a device.
Navigator.cookieEnabled Read only
Returns false if setting a cookie will be ignored and true otherwise.
Navigator.credentials Read only
Returns the CredentialsContainer interface which exposes methods to request credentials and notify the user agent when interesting events occur such as successful sign in or sign out. 
Navigator.deviceMemory Read only This is an experimental API that should not be used in production code.
Returns the amount of device memory in gigabytes. This value is an approximation given by rounding to the nearest power of 2 and dividing that number by 1024.
Navigator.doNotTrack Read only This is an experimental API that should not be used in production code.
Reports the value of the user's do-not-track preference. When this value is "yes", your web site or application should not track the user.
Navigator.geolocation Read only
Returns a Geolocation object allowing accessing the location of the device.
NavigatorConcurrentHardware.hardwareConcurrency Read only
Returns the number of logical processor cores available.
NavigatorPlugins.javaEnabled Read only
Returns a Boolean flag indicating whether the host browser is Java-enabled or not.
Navigator.keyboard Read only This is an experimental API that should not be used in production code.
Returns a Keyboard object which provides access to functions that retrieve keyboard layout maps and toggle capturing of key presses from the physical keyboard.
NavigatorLanguage.language Read only
Returns a DOMString representing the preferred language of the user, usually the language of the browser UI. The null value is returned when this is unknown.
NavigatorLanguage.languages Read only This is an experimental API that should not be used in production code.
Returns an array of DOMString representing the languages known to the user, by order of preference.
Navigator.locks Read only This is an experimental API that should not be used in production code.
Returns a LockManager object which provides methods for requesting a new Lock object and querying for an existing Lock object
Navigator.maxTouchPoints Read only
Returns the maximum number of simultaneous touch contact points are supported by the current device.
Navigator.mediaCapabilities Read only This is an experimental API that should not be used in production code.
Returns a MediaCapabilities object that can expose information about the decoding and encoding capabilities for a given format and output capabilities.
Navigator.mediaDevices Read only
Returns a reference to a MediaDevices object which can then be used to get information about available media devices (MediaDevices.enumerateDevices()), find out what constrainable properties are supported for media on the user's computer and user agent (MediaDevices.getSupportedConstraints()), and to request access to media using MediaDevices.getUserMedia().
Navigator.mediaSession Read only This is an experimental API that should not be used in production code.
Returns MediaSession object which can be used to provide metadata that can be used by the browser to present information about the currently-playing media to the user, such as in a global media controls UI.
NavigatorPlugins.mimeTypes Read only
Returns an MimeTypeArray listing the MIME types supported by the browser.
Navigator.onLine Read only
Returns a Boolean indicating whether the browser is working online.
Navigator.permissions Read only This is an experimental API that should not be used in production code.
Returns a Permissions object that can be used to query and update permission status of APIs covered by the Permissions API.
NavigatorPlugins.plugins Read only
Returns a PluginArray listing the plugins installed in the browser.
Navigator.presentation Read only This is an experimental API that should not be used in production code.
Returns a reference to the Presentation API.
Navigator.serviceWorker Read only
Returns a ServiceWorkerContainer object, which provides access to registration, removal, upgrade, and communication with the ServiceWorker objects for the associated document.
NavigatorStorage.storage Read only
Returns the singleton StorageManager object used for managing persistence permissions and estimating available storage on a site-by-site/app-by-app basis.
NavigatorID.userAgent Read only
Returns the user agent string for the current browser.
Navigator.vendor Read only
Returns the vendor name of the current browser (e.g., "Netscape6").
Navigator.webdriver Read only  This is an experimental API that should not be used in production code.
Indicates whether the user agent is controlled by automation.
Navigator.xr Read only  This is an experimental API that should not be used in production code.
Returns XR object, which represents the entry point into the WebXR API.

Non-standard properties

Navigator.buildID This API has not been standardized.
Returns the build identifier of the browser. In modern browsers this property now returns a fixed timestamp as a privacy measure, e.g. 20181001000000 in Firefox 64 onwards.
Navigator.contacts Read only This API has not been standardized.
Returns a ContactsManager interface which allows users to select entries from their contact list and share limited details of the selected entries with a website or application.
Navigator.securitypolicy This API has not been standardized.
Returns an empty string. In Netscape 4.7x, returns "US & CA domestic policy" or "Export policy".
Navigator.standalone This API has not been standardized.
Returns a boolean indicating whether the browser is running in standalone mode. Available on Apple's iOS Safari only.
Navigator.wakeLock Read only This API has not been standardized.
Returns a WakeLock interface you can use to request screen wake locks and prevent screen from dimming, turning off, or showing a screen saver.

Deprecated properties

NavigatorID.appCodeName Read only This deprecated API should no longer be used, but will probably still work.
Returns the internal "code" name of the current browser. Do not rely on this property to return the correct value.
NavigatorID.appName Read only This deprecated API should no longer be used, but will probably still work.
Returns a DOMString with the official name of the browser. Do not rely on this property to return the correct value.
NavigatorID.appVersion Read only This deprecated API should no longer be used, but will probably still work.
Returns the version of the browser as a DOMString. Do not rely on this property to return the correct value.
Navigator.activeVRDisplays Read only This deprecated API should no longer be used, but will probably still work.
Returns an array containing every VRDisplay object that is currently presenting (VRDisplay.ispresenting is true).
Navigator.battery Read only This deprecated API should no longer be used, but will probably still work.
Returns a BatteryManager object you can use to get information about the battery charging status.
Navigator.oscpu Read only This deprecated API should no longer be used, but will probably still work.
Returns a string that represents the current operating system.
NavigatorID.platform Read only This deprecated API should no longer be used, but will probably still work.
Returns a string representing the platform of the browser. Do not rely on this function to return a significant value.
NavigatorID.product Read only This deprecated API should no longer be used, but will probably still work.
Always returns 'Gecko', on any browser. This property is kept only for compatibility purpose.
Navigator.productSub Read only This deprecated API should no longer be used, but will probably still work.
Returns the build number of the current browser (e.g., "20060909").
Navigator.storageQuota Read only This deprecated API should no longer be used, but will probably still work.
Returns a StorageQuota interface which provides means to query and request storage usage and quota information.
Navigator.vendorSub Read only This deprecated API should no longer be used, but will probably still work.
Returns the vendor version number (e.g. "6.1").

Methods

Doesn't inherit any method, but implements those defined in NavigatorID, NavigatorContentUtils, NavigatorUserMedia, and NavigatorStorageUtils.

Navigator.canShare()
Returns true if a call to Navigator.share() would succeed.
Navigator.registerProtocolHandler()
Allows web sites to register themselves as a possible handler for a given protocol.
Navigator.requestMediaKeySystemAccess()
Returns a Promise for a MediaKeySystemAccess object.
Navigator.sendBeacon()
Used to asynchronously transfer a small amount of data using HTTP from the User Agent to a web server.
Navigator.share()
Invokes the native sharing mechanism of the current platform.
Navigator.vibrate()
Causes vibration on devices with support for it. Does nothing if vibration support isn't available.

Deprecated methods

Navigator.getVRDisplays() This deprecated API should no longer be used, but will probably still work.
Returns a promise that resolves to an array of VRDisplay objects representing any available VR devices connected to the computer.
Navigator.getUserMedia() This deprecated API should no longer be used, but will probably still work.
After having prompted the user for permission, returns the audio or video stream associated to a camera or microphone on the local computer.
Navigator.registerContentHandler() This deprecated API should no longer be used, but will probably still work.
Allows web sites to register themselves as a possible handler for a given MIME type.
NavigatorID.taintEnabled() This deprecated API should no longer be used, but will probably still work.
Returns false. JavaScript taint/untaint functions removed in JavaScript 1.2.

Specifications

SpecificationStatusComment
HTML Living Standard
The definition of 'the Navigator object' in that specification.
Living Standard

Browser compatibility

BCD tables only load in the browser

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:149 次

字数:41324

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文