예제 10-13: Screen 객체 및 Window vs Screen 분석 문서

본 문서는 브라우저 창 환경을 다루는 `window` 객체와 사용자 모니터 디스플레이 화면 정보를 다루는 `screen` 객체의 차이점을 정리하고, 화면 해상도 및 색상 깊이를 조회하는 기능을 설명합니다.

1. Window 객체 vs Screen 객체 차이점 비교

JavaScript에서 window와 screen은 모두 브라우저 환경을 파악하는 데 쓰이지만, 관리하는 대상의 범위가 명확히 다릅니다.

💡 핵심 차이 요약:

1) Screen 객체의 주요 특징

screen 객체는 접두사 없이 사용 가능하며(window.screen의 단축형), 사용자의 디바이스 환경(모니터 해상도, 가용 작업 표시줄 영역 등)을 조회할 때 유용합니다.

2. 제공된 HTML 원본 코드

<!DOCTYPE html>
<html>
<head>
	<link rel="stylesheet" href="style.css">
<meta charset="utf-8">
<title>예제 10-13 Screen 객체</title>
</head>
<body>
<p>Screen 크기는 <b id="wh"></b>입니다.</p>
<p>Screen 가능한 크기는 <b id="awh"></b>입니다.</p>
<p>Screen 색상은 <b id="cd"></b> 비트입니다.</p>
<p>Screen 픽셀은 <b id="pd"></b> 비트입니다.</p>
<h3>Screen 객체</h3>
<button type="button" onclick="wH()">화면 크기</button>
<button type="button" onclick="aWh()">가용 크기</button>
<button type="button" onclick="cD()">칼라 깊이</button>
<button type="button" onclick="pD()">픽셀 깊이</button>
<script>
	function wH() {   
		var w = screen.width, h = screen.height; 
		document.getElementById("wh").textContent = "w:" + w + " h:" + h; 
	}
	function aWh() {   
		var w = screen.availWidth, h = screen.availHeight; 
		document.getElementById("awh").textContent = "w:" + w + " h:" + h;
	}
	function cD() {   
		var c = screen.colorDepth;
		document.getElementById("cd").textContent = "color:" + c; 	
	}
	function pD() { 
		var p = screen.pixelDepth;    
		document.getElementById("pd").textContent = "pixel:" + p; 
	}
</script>
</body>
</html>

실시간 실행 화면

Screen 크기는 입니다.

Screen 가능한 크기는 입니다.

Screen 색상은 비트입니다.

Screen 픽셀은 비트입니다.

Screen 객체 제어

3. Screen 객체 주요 속성 상세 분석

속성명 사용 예시 동작 설명 및 특징
screen.width / height screen.width, screen.height 사용자의 모니터 디스플레이 전체 물리적 해상도(너비와 높이)를 픽셀 단위로 반환합니다.
screen.availWidth / availHeight screen.availWidth, screen.availHeight 모니터 전체 화면 중 작업 표시줄(Taskbar) 등을 제외하고 브라우저가 실제로 사용할 수 있는 가용 영역의 크기를 반환합니다.
screen.colorDepth screen.colorDepth 화면 색상을 표현하는 데 사용되는 색상 팔레트의 비트 깊이(예: 24비트 등)를 반환합니다.
screen.pixelDepth screen.pixelDepth 화면의 픽셀 당 비트(Bit) 수를 반환합니다. 대부분의 모니터에서는 colorDepth와 동일한 값을 가집니다.

핵심 정리

학습 포인트: 브라우저 창 관점(`window`)과 물리적 모니터 관점(`screen`)의 차이를 이해하고 디스플레이 정보를 조회하는 방법을 익힙니다.