Screen interface represents a screen, usually the one on which the current window is being rendered, and is obtained using window.screen .

Note that browsers determine which screen to report as current by detecting which screen has the center of the browser window.

特性

Screen.availTop

Specifies the y-coordinate of the first pixel that is not allocated to permanent or semipermanent user interface features.

Screen.availLeft

Returns the first available pixel available from the left side of the screen.

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

Returns the amount of horizontal space in pixels available to the window.

Screen.colorDepth

Returns the color depth of the screen.

Screen.height

Returns the height of the screen in pixels.

Screen.left

Returns the distance in pixels from the left side of the main screen to the left side of the current screen.

Screen.orientation
返回 ScreenOrientation instance associated with this screen.
Screen.pixelDepth

Gets the bit depth of the screen.

Screen.top

Returns the distance in pixels from the top side of the current screen.

Screen.width

Returns the width of the screen.

Screen.mozEnabled

Boolean. Setting to false will turn off the device's screen.

Screen.mozBrightness

Controls the brightness of a device's screen. A double between 0 and 1.0 is expected.

Events handler

Screen.onorientationchange
处理程序为 orientationchange 事件。

方法

Screen.lockOrientation

Lock the screen orientation (only works in fullscreen or for installed apps)

Screen.unlockOrientation

Unlock the screen orientation (only works in fullscreen or for installed apps)

Methods inherited from EventTarget :

EventTarget .addEventListener()
注册特定事件类型的事件处理程序在 EventTarget .
EventTarget .removeEventListener()
移除事件监听器从 EventTarget .
EventTarget .dispatchEvent()
把事件分派给此 EventTarget .

额外 Mozilla Chrome 代码库方法

Mozilla 包括 2 个扩展,供由 JS 实现的事件目标用于实现 on event 特性。

另请参阅 WebIDL 绑定 .

  • 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
}
					

规范

规范 状态 注释
CSSOM (CSS 对象模型) 视图模块
The definition of 'Screen' in that specification.
工作草案 初始定义。

浏览器兼容性

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. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
Screen Chrome Yes Edge 12 Firefox Yes IE Yes Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
availHeight Chrome 40 Edge 12
12
Always reflects the main screen.
Firefox Yes IE ? Opera Yes Safari 6 WebView Android 40 Chrome Android 40 Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android 4.0
availLeft 非标 Chrome Yes Edge 79 Firefox Yes IE ? Opera Yes Safari 6 WebView Android Yes Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS ? Samsung Internet Android Yes
availTop 非标 Chrome 40 Edge 79 Firefox Yes IE ? Opera Yes Safari 6 WebView Android 40 Chrome Android 40 Firefox Android Yes Opera Android Yes Safari iOS ? Samsung Internet Android 4.0
availWidth Chrome Yes Edge 12
12
Always reflects the main screen.
Firefox Yes IE ? Opera Yes Safari 6 WebView Android Yes Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
colorDepth Chrome 40
40
Starting with version 59 this property is no longer required to always return 24.
Edge 12 Firefox Yes IE ? Opera Yes Safari 6 WebView Android 40
40
Starting with version 59 this property is no longer required to always return 24.
Chrome Android 40
40
Starting with version 59 this property is no longer required to always return 24.
Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android 4.0
4.0
Starting with Samsung Internet 7.0 this property is no longer required to always return 24.
height Chrome Yes Edge 12 Firefox Yes IE ? Opera Yes Safari 6 WebView Android Yes Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
left 非标 Chrome No Edge ≤18 — 79 Firefox Yes IE ? Opera No Safari Yes WebView Android No Chrome Android No Firefox Android Yes Opera Android No Safari iOS ? Samsung Internet Android No
lockOrientation Chrome 38 Edge 12 Prefixed
12 Prefixed
Prefixed Implemented with the vendor prefix: ms
Firefox Yes Prefixed
Yes Prefixed
Prefixed Implemented with the vendor prefix: moz
IE 11 Prefixed
11 Prefixed
Prefixed Implemented with the vendor prefix: ms
Opera Yes Safari No WebView Android 38 Chrome Android 38 Firefox Android Yes Prefixed
Yes Prefixed
Prefixed Implemented with the vendor prefix: moz
Opera Android Yes Safari iOS No Samsung Internet Android 3.0
mozBrightness 弃用 非标 Chrome No Edge No Firefox 12 IE No Opera No Safari No WebView Android No Chrome Android No Firefox Android 14 Opera Android No Safari iOS No Samsung Internet Android No
mozEnabled 弃用 非标 Chrome No Edge No Firefox 12 IE No Opera No Safari No WebView Android No Chrome Android No Firefox Android 14 Opera Android No Safari iOS No Samsung Internet Android No
onorientationchange Chrome No Edge ≤18 — 79 Alternate Name
不支持 ≤18 — 79 Alternate Name
Alternate Name Uses the non-standard name: onmsorientationchange
Firefox No IE No Opera No Safari No WebView Android No Chrome Android No Firefox Android Yes Alternate Name
Yes Alternate Name
Alternate Name Uses the non-standard name: onmozorientationchange
Opera Android No Safari iOS No Samsung Internet Android No
orientation Chrome 38 Edge 12 Prefixed
12 Prefixed
Prefixed Implemented with the vendor prefix: ms
Edge does not return an 取向 object; instead, it returns the orientation type as a string.
Firefox Yes
Yes
Yes Prefixed
Prefixed Implemented with the vendor prefix: moz
IE 11 Prefixed
11 Prefixed
Prefixed Implemented with the vendor prefix: ms
Not supported on Windows 7.
Opera 25 Safari No WebView Android No Chrome Android 39 Firefox Android Yes
Yes
Yes Prefixed
Prefixed Implemented with the vendor prefix: moz
Opera Android No Safari iOS No Samsung Internet Android 4.0
pixelDepth Chrome 40
40
Starting with version 59 this property is no longer required to always return 24.
Edge 12 Firefox Yes IE ? Opera Yes Safari 6 WebView Android Yes
Yes
Starting with version 59 this property is no longer required to always return 24.
Chrome Android Yes
Yes
Starting with version 59 this property is no longer required to always return 24.
Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android Yes
Yes
Starting with Samsung Internet 7.0 this property is no longer required to always return 24.
top 弃用 非标 Chrome No Edge ≤18 — 79 Firefox Yes IE ? Opera No Safari Yes WebView Android No Chrome Android No Firefox Android Yes Opera Android No Safari iOS ? Samsung Internet Android No
unlockOrientation Chrome 38 Edge 12 Prefixed
12 Prefixed
Prefixed Implemented with the vendor prefix: ms
Firefox Yes Prefixed
Yes Prefixed
Prefixed Implemented with the vendor prefix: moz
IE 11 Prefixed
11 Prefixed
Prefixed Implemented with the vendor prefix: ms
Opera Yes Safari No WebView Android 38 Chrome Android 38 Firefox Android Yes Prefixed
Yes Prefixed
Prefixed Implemented with the vendor prefix: moz
Opera Android Yes Safari iOS No Samsung Internet Android 3.0
width Chrome 40 Edge 12 Firefox Yes IE ? Opera Yes Safari 6 WebView Android 40 Chrome Android 40 Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android 4.0

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

非标。预期跨浏览器支持较差。

非标。预期跨浏览器支持较差。

弃用。不要用于新网站。

弃用。不要用于新网站。

见实现注意事项。

用户必须明确启用此特征。

用户必须明确启用此特征。

使用非标名称。

要求使用供应商前缀或不同名称。

要求使用供应商前缀或不同名称。

元数据

  • 最后修改: