브라우저 크기 조절 시 화면에 출력

 

window.screen → 모니터 사이즈

window.outer → 페이지를 넘어서 브라우저에 있는 URL, 탭 포함 브라우저 사이즈

window.inner → 브라우저 내 컨텐츠(스크롤바 포함)

documentElement.clientWidth → 현재 문서 사이즈(스크롤바 제외)

 

 

window.addEventListener("resize",); 이용하면 아래와 같은 것들을 가져올 수 있다.

 window.screen.width, window.screen.height

 window.outerWidth, window.outerHeight

 window.innerWidth, window.innerHeight

 document.documentElement.clientWidth, document.documentElement.clientHeight

 

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Window Size</title>
    <style>
        .tag {
            display: inline-block;
            background-color: thistle;
            padding: 16px;
            margin-top: 16px;
            font-size: 48px;
        }
    </style>
</head>
<body>
    <div class="tag">window.screen</div>

    <script>
        const tag = document.querySelector('.tag');
        
        function updateTag() {
            tag.innerHTML = `window.screen:${window.screen.width}, ${window.screen.height} </br>
                            window.outer:${window.outerWidth}, ${window.outerHeight} </br>
                            window.inner:${window.innerWidth}, ${window.innerHeight} </br>
                            documentElement.clientWidth:${document.documentElement.clientWidth}, ${document.documentElement.clientHeight}`;
        }

        updateTag();

        window.addEventListener("resize", () => {
            updateTag();
        });
    </script>
</body>
</html>

 

[드림코딩] 윈도우 사이즈 가져오기