Screen 接口表示一个屏幕窗口,往往指的是当前正在被渲染的window对象,可以使用 window.screen 获取它。

请注意:由浏览器决定提供屏幕对象,此对象一般通过当前浏览器窗口活动状态动态检测来得到。

属性

Screen.availTop
Specifies the y-coordinate of the first pixel that is not allocated to permanent or semipermanent user interface features.
Screen.availLeft
返回屏幕左边边界的第一个像素点
Screen.availHeight
Specifies the height of the screen, in pixels, minus permanent or semipermanent user interface features displayed by the operating system, such as the Taskbar on Windows.
Screen.availWidth
返回窗口中水平方向可用空间的像素值。
Screen.colorDepth
返回屏幕的色彩深度。
Screen.height
以像素为单位返回屏幕的高度。
Screen.left
返回从最左边界到当前屏幕的像素值。
Screen.orientation
返回当前屏幕的转向。
Screen.pixelDepth
获取屏幕的像素点
Screen.top
返回最上边界到当前屏幕的像素值。
Screen.width
返回屏幕的宽度。
Screen.mozEnabled
布尔值。如果设置为false讲关闭设备的屏幕。
Screen.mozBrightness
控制设备屏幕的亮度。期望参数是0-1.0之间的浮点数。

Events handler

Screen.onorientationchange
orientationchange 事件的时间处理器。
 

方法

Screen.lockOrientation
锁定屏幕转向(仅在全屏或者已安装的APP中生效)
Screen.unlockOrientation
解锁屏幕转向(仅在全屏或者已安装的APP中生效)

方法继承于 EventTarget

EventTarget.addEventListener()
Registers an event handler of a specific event type on the EventTarget.
EventTarget.removeEventListener()
Removes an event listener from the EventTarget.
EventTarget.dispatchEvent()
Dispatches an event to this EventTarget.

Additional methods for Mozilla chrome code

Mozilla includes a couple of extensions for use by JS-implemented event targets to implement onevent properties. See also WebIDL bindings.

  • void setEventHandler(DOMString type, EventHandler handler)
  • EventHandler getEventHandler(DOMString type)

示例

if (screen.pixelDepth < 8) {
  // use low-color version of page
} else { 
  // use regular, colorful page
}

标准文档说明

Specification Status Comment
CSS Object Model (CSSOM) View Module
Screen
Working Draft  

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
ScreenChrome Full support YesEdge Full support YesFirefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
availHeightChrome Full support 40Edge Full support 12
Notes
Full support 12
Notes
Notes Always reflects the main screen.
Firefox Full support YesIE ? Opera Full support YesSafari Full support 6WebView Android Full support 40Chrome Android Full support 40Edge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
availLeft
Non-standard
Chrome Full support YesEdge No support NoFirefox Full support YesIE ? Opera Full support YesSafari Full support 6WebView Android Full support YesChrome Android Full support YesEdge Mobile No support NoFirefox Android Full support YesOpera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
availTop
Non-standard
Chrome Full support 40Edge No support NoFirefox Full support YesIE ? Opera Full support YesSafari Full support 6WebView Android Full support 40Chrome Android Full support 40Edge Mobile No support NoFirefox Android Full support YesOpera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
availWidthChrome Full support YesEdge Full support 12
Notes
Full support 12
Notes
Notes Always reflects the main screen.
Firefox Full support YesIE ? Opera Full support YesSafari Full support 6WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
colorDepthChrome Full support 40
Notes
Full support 40
Notes
Notes Starting with version 59 this property is no longer required to always return 24.
Edge Full support 12Firefox Full support YesIE ? Opera Full support YesSafari Full support 6WebView Android Full support 40
Notes
Full support 40
Notes
Notes Starting with version 59 this property is no longer required to always return 24.
Chrome Android Full support 40
Notes
Full support 40
Notes
Notes Starting with version 59 this property is no longer required to always return 24.
Edge Mobile ? Firefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
heightChrome Full support YesEdge Full support 12Firefox Full support YesIE ? Opera Full support YesSafari Full support 6WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
left
Non-standard
Chrome Full support YesEdge Full support YesFirefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
lockOrientationChrome Full support 38Edge ? Firefox Full support Yes
Prefixed
Full support Yes
Prefixed
Prefixed Implemented with the vendor prefix: moz
IE Full support 11
Prefixed
Full support 11
Prefixed
Prefixed Implemented with the vendor prefix: ms
Opera Full support YesSafari No support NoWebView Android Full support 38Chrome Android Full support 38Edge Mobile ? Firefox Android Full support Yes
Prefixed
Full support Yes
Prefixed
Prefixed Implemented with the vendor prefix: moz
Opera Android Full support YesSafari iOS No support NoSamsung Internet Android Full support Yes
mozBrightness
DeprecatedNon-standard
Chrome No support NoEdge No support NoFirefox Full support 12
Disabled
Full support 12
Disabled
Disabled From version 12: this feature is behind the dom.screenBrightnessProperty.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android Full support 14
Disabled
Full support 14
Disabled
Disabled From version 14: this feature is behind the dom.screenBrightnessProperty.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
mozEnabled
DeprecatedNon-standard
Chrome No support NoEdge No support NoFirefox Full support 12
Disabled
Full support 12
Disabled
Disabled From version 12: this feature is behind the dom.screenEnabledProperty.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android Full support 14
Disabled
Full support 14
Disabled
Disabled From version 14: this feature is behind the dom.screenEnabledProperty.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
onorientationchangeChrome No support NoEdge No support NoFirefox No support NoIE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android Full support Yes
Alternate Name
Full support Yes
Alternate Name
Alternate Name Uses the non-standard name: onmozorientationchange
Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
orientationChrome Full support 38Edge ? Firefox Full support Yes
Full support Yes
Full support Yes
Prefixed
Prefixed Implemented with the vendor prefix: moz
IE Full support 11
Prefixed Notes
Full support 11
Prefixed Notes
Prefixed Implemented with the vendor prefix: ms
Notes Not supported on Windows 7.
Opera Full support 25Safari No support NoWebView Android No support NoChrome Android Full support 39Edge Mobile ? Firefox Android Full support Yes
Full support Yes
Full support Yes
Prefixed
Prefixed Implemented with the vendor prefix: moz
Opera Android No support NoSafari iOS No support NoSamsung Internet Android Full support Yes
pixelDepthChrome Full support 40
Notes
Full support 40
Notes
Notes Starting with version 59 this property is no longer required to always return 24.
Edge Full support 12Firefox Full support YesIE ? Opera Full support YesSafari Full support 6WebView Android Full support Yes
Notes
Full support Yes
Notes
Notes Starting with version 59 this property is no longer required to always return 24.
Chrome Android Full support Yes
Notes
Full support Yes
Notes
Notes Starting with version 59 this property is no longer required to always return 24.
Edge Mobile ? Firefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
top
DeprecatedNon-standard
Chrome Full support YesEdge Full support YesFirefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
unlockOrientationChrome Full support 38Edge ? Firefox Full support Yes
Prefixed
Full support Yes
Prefixed
Prefixed Implemented with the vendor prefix: moz
IE Full support 11
Prefixed
Full support 11
Prefixed
Prefixed Implemented with the vendor prefix: ms
Opera Full support YesSafari No support NoWebView Android Full support 38Chrome Android Full support 38Edge Mobile ? Firefox Android Full support Yes
Prefixed
Full support Yes
Prefixed
Prefixed Implemented with the vendor prefix: moz
Opera Android Full support YesSafari iOS No support NoSamsung Internet Android Full support Yes
widthChrome Full support 40Edge Full support 12Firefox Full support YesIE ? Opera Full support YesSafari Full support 6WebView Android Full support 40Chrome Android Full support 40Edge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.
Uses a non-standard name.
Uses a non-standard name.
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.
 

文档标签和贡献者

标签: 
最后编辑者: lizheming,