본문 바로가기
국비 과정/JavaScript

국비 - 0927 ( Screen )

by 코딩호야 2022. 9. 27.

* Screen 객체

screen은 브라우저가 실행되는 스크린 장치에 관한 정보를 담고 있는 객체이다.

screen 객체는 다음과 같이 접근한다.
window.screen 혹은 screen


* screen 객체의 프로퍼티

. availHeight    // 작업 표시줄 등을 제외하고 브라우저가 출력 가능한 영역의 높이

. availWidth    // 작업 표시줄 등을 제되하고 브라우저가 출력가능한 영역의 폭

. pixelDepth    // 한 픽셀의 색을 나타내기 위해 사용되는 비트 수
. colorDepth    // 한 픽셀의 색을 나타내기 위해 사용되는 비트 수로서 pixelDepth 와 동일 .
                    대부분의 브라우저에서 지원되므로 pixelDepth 보다 colorDepth 를 사용 할 것을 권함

. availHeight   // 스크린의 수직 픽셀 수
. width         // 스크린의 수평 픽셀 수

    <title>스크린에 관한 정보 출력</title>
    <script>
        function printScreen(){
            var text = "avaiHeight : "+screen.availHeight + "<br>";
                text += "avaiWidth : "+ screen.availWidth + "<br>";
                text += "colorDepth : "+ screen.colorDepth + "<br>";
                text += "pixelDepth : "+ screen.pixelDepth + "<br>";
                text += "height : "+ screen.height + "<br>";
                text += "width : "+ screen.width + "<br>";
            document.getElementById("div").innerHTML = text;
        }
    </script>
</head>
<body onload="printScreen()">
    <h3>스크린 장치에 관한 정보</h3>
    <hr>
    <div id="div"></div>
    
</body>

위코드를 실행한 결과



. history 객체

history 객체는 사용자가 방문한 웹 페이지의 리스트, 즉 히스토리 정보를 담고 있는 객체로 다음과 같이 접근한다.

window.history 혹은 history

. history.back(); 또는 history.go(-1);   // 이전 페이지로 이동
. history.forward(); 또는 history.go(1);   // 다음 페이지로 이동

.history 객체의 프로퍼티와 메서드

프로퍼티

.length         // 히스토리 리스트에 있는 엔트리 수

메서드
.back()         // 히스토리에 있는 이전 웹 페이지로 이동. 브라우저 <back> 버튼과 동일
.forward()      // 히스토리에 있는 다음 웹 페이지로 이동. 브라우저의 <forward> 버튼과 동일
.go(n)         // 히스토리에서 현재 웹페이지에서 n 만큼 상대적인 웹페이지로 이동

    <title>history 객체</title>
    <script>
        document.write("방문한 페이지 수 : "+hitory.length);
    </script>
</head>

<body>
    <h3>history 객체 연습 ( 첫 번째 페이지)</h3>
    <a href="test1.html">다음 페이지</a><br><Br>
        <input type="button" value="이전으로11" onclick="javascript:history.back()">
        <input type="button" value="다음으로11" onclick="history.forward()">
        <input type="button" value="처음으로11" onclick="history.go(-2)">
    
</body>
    <title>history 객체 test1.html</title>
    <script>
        document.write("방문한 페이지 수 : "+ history.length);
    </script>
</head>
<body>
    <h3>history 객체 연습(두 번째 페이지)</h3>
    <a href="test2.html">다음 페이지</a><br><Br>
        <input type="button" value="이전으로22" onclick="javascript:history.back()">
        <input type="button" value="다음으로22" onclick="history.forward()">
        <input type="button" value="처음으로22" onclick="history.go(-2)">
    
</body>
    <title>History 객체 test2.html</title>
    <script>
        document.write("방문한 페이지 수 : "+ history.length);

    </script>
</head>
<body>
    <h3>History 객체 연습(세번째 페이지)</h3><br><br>
    <a href="test3.html">다음 페이지</a><br><Br>
    <input type="button" value="이전으로33" onclick="javascript:history.back()">
    <input type="button" value="다음으로33" onclick="history.forward()">
    <input type="button" value="처음으로33" onclick="history.go(-2)">
    
</body>

 

TEST로 세개까지 웹 창을 만들어 놓고 history 를 적용 시켜봤다.

 

위 이미지 처럼 앞 과 뒤로 history 를 통해 이동할수 있으며 go(-2) 를 처음으로에 적용시켜서 세번쨰페이지에서 한번에

첫번째 페이지로 이동이 가능하다.