js如何获取浏览器分辨率
1、打开html开发工具,新建一个html代码页面。

2、在html代码页面新建一个<script>,使用window.screen.width、window.screen.height获取电脑当前的分辨率之栗,最后使用document.write把电脑当前分辨肺亲率打印到浏览器上。
代码:
<script>
window.onload = function () {
document.write("浏览器宽:"+window.screen.width +
"<br />浏览器高:"+window.screen.height)
}
</script>

3、使用浏览器打开html代码页面(案例中使用的Google浏览器),这个时候可以看到浏览器上打印出浏览器宽:1920 浏览器高:1080。

4、为了验证window.screen.width、window.screen.height是否根根据不同浏览器获取不同的分辨率。我们按F12,然后选择浏览器下方的Toggle device toolbar按钮。

5、重新刷新浏览器,这个时候会看到浏览器页面上显示的宽、高已经发生了改变。

6、所有代码。可以直接复制所有代码,复制粘贴到新建html页面,保存后按F12后点击Console即可看到效果。
所有代码扬驾救:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
window.onload = function () {
document.write("浏览器宽:"+window.screen.width +
"<br />浏览器高:"+window.screen.height)
}
</script>
</body>
</html>
