屏幕宽度属性用于返回用户屏幕的总宽度。它以像素为单位返回屏幕的总宽度。
用法:
screen.width
以下示例程序旨在说明Screen width属性:
检查用户屏幕的总宽度。
Screen width Property in HTML
h1 {
color:green;
}
h2 {
font-family:Impact;
}
body {
text-align:center;
}
GeeksforGeeks
Screen width Property
For checking the screen's width,
double click the "Check width" button:
Check width
function width() {
var w = "Total Screen Width in Pixels:"
+ screen.width;
document.getElementById("wd").innerHTML = w;
}
输出:
单击按钮后
支持的浏览器:屏幕宽度支持的浏览器如下:
谷歌浏览器
IE浏览器
Firefox
Opera
Safari