Returns the width of the screen.

句法

lWidth = window.screen.width
					

范例

// Crude way to check that the screen is at least 1024x768
if (window.screen.width >= 1024 && window.screen.height >= 768) {
  // Resolution is 1024x768 or above
}
					

注意事项

Note that not all of the width given by this property may be available to the window itself. When other widgets occupy space that cannot be used by the window object, there is a difference in window.screen.width and window.screen.availWidth 。另请参阅 screen.height .

Internet Explorer will take into account the zoom setting when reporting the screen width. It will only return the real width of the screen if the zoom is set to 100%.

规范

规范 状态 注释
CSSOM (CSS 对象模型) 视图模块
The definition of 'Screen.width' 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
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

图例

完整支持

完整支持

兼容性未知 ?

兼容性未知

元数据

  • 最后修改: