본문 바로가기
JS/JS-event

BOM -네비게이터 객체

by 임혁진 2024. 2. 5.

네비게이터

-현재 브라우저에 대한 정보를 제공하는 객체

  <script>
        console.log(navigator.userAgent)
    </script>

 

접속 브라우저에 따른 화면설계하기 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    

    <h3>네비게이터 객체 </h3>

    <div class = "wrap">
        내용.........................
    </div>

    <script>
        // console.log(navigator.userAgent)
        var head = document.querySelector("head"); //head태그
        var link = document.createElement("link"); //link 태그
        link.rel = "stylesheet";
        

        if(navigator.userAgent.includes("Mobile")){
            alert("모바일 환경으로 접속합니다. redirect 시킵니다");

            link.href = "mobil.css";

        }else if(navigator.userAgent.includes("Chrome")){
            alert("크롬환경으로접속합니다. redirect시킵니다");

            link.href = "chrome.css"
            
        } // 생략

        head.appendChild(link); //head 마지막에 link를 추가한다.
    </script>

</body>
</html>

 

'JS > JS-event' 카테고리의 다른 글

BOM - history  (0) 2024.02.05
노드 삭제  (1) 2024.02.05
BOM - timeout  (0) 2024.02.05
요소생성 - 노드생성 및 추가  (0) 2024.02.05
BOM -인터벌예제  (0) 2024.02.05