javaScript 屏幕宽高,浏览器宽高

javaScript 屏幕宽高,浏览器宽高

记录下js取得屏幕,浏览器宽高的方法, 方便以后查看.

通过写简单html页面进行验证. 调整浏览器位置,大小后,刷新页面,查看控制台输出.
(如有错漏,请指正.谢谢!)

<!DOCTYPE html>
<html>
<head>
	<title>test</title>
	<script type="text/javascript">
		console.log('===========================================================')
		console.log(window.screen.height + '	window.screen.height');
		console.log(window.screen.availHeight + '	window.screen.availHeight');
		console.log(window.outerHeight + '	window.outerHeight');
		console.log(window.innerHeight + '	window.innerHeight');
		console.log(document.documentElement.clientHeight + '	document.documentElement.clientHeight');
		//console.log(document.body.clientHeight); //此行会报错,我是菜鸟,不懂原因
		console.log('===========================================================')
		console.log(window.screen.width + '	window.screen.width');
		console.log(window.screen.availWidth + '	window.screen.availWidth');
		console.log(window.outerWidth + '	window.screen.outerWidth');
		console.log(window.innerWidth + '	window.screen.innerWidth');
		console.log(document.documentElement.clientWidth + '	document.documentElement.clientWidth');
		//console.log(document.body.clientWidth); //此行会报错,我是菜鸟,不懂原因
	</script>
</head>
<body>
宽高
</body>
</html>

结果

在这里插入图片描述
总结如下:
在这里插入图片描述

上图红色线从上到下, 依次是
  1. window.screen.width
    电脑屏幕宽度
  2. window.screen.availWidth
    电脑屏幕除去左右两侧工具栏的宽度(上图中左右两侧没有工具栏)
  3. window.outerWidth
    整个浏览器的宽度(包括浏览器侧边工具栏及浏览器边框)
  4. window.innerWidth
    浏览器内部可见区的宽度(包括浏览器滚动条,但不包括浏览器侧边工具栏)
  5. document.documentElement.clientWidth
    浏览器内部可见区的宽度(包括浏览器滚动条,但不包括浏览器侧边工具栏)
上图紫色线从左到右, 依次是
  1. window.screen.height
    电脑屏幕高度
  2. window.screen.availHeight
    电脑屏幕除去顶部及底部工具栏的高度
  3. window.outerHeight
    整个浏览器的高度(包括浏览器工具栏,状态栏,…,及浏览器边框)
  4. window.innerHeight
    浏览器内部可见区的高度(包括浏览器滚动条,但不包括浏览器工具栏,状态栏)
  5. document.documentElement.clientHeight
    浏览器内部可见区的高度(包括浏览器滚动条,但不包括浏览器工具栏,状态栏)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值