• 회원가입
  • 로그인
  • 구글아이디로 로그인

[Window_Navigator] JS - navigator.userAgent 속성 - 사용자 브라우저 정보 반환 (= navigator.userAgent속성 = 네비게이터유저에이전트속성)

목차

  1. navigator.userAgent 예제 - 사용자 브라우저 정보 반환
  2. navigator.userAgent 정의
  3. navigator.userAgent 구문
  4. navigator.userAgent 예제 - navigator 관련 모든 속성 표시
  5. navigator.userAgent 예제 - 브라우저별 분기 조건문

 

navigator.userAgent 예제 - 사용자 브라우저 정보 반환

 

<p id="demo"></p>


<script>

let agent = navigator.userAgent;

document.getElementById("demo").innerHTML = "사용자 브라우저 정보:<br>" + agent;

</script>

 

결과보기 (예) Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

 

navigator.userAgent 정의

 

브라우저에서 서버로 보낸 사용자 에이전트 헤더 반환.

(즉, 서버로 전달된 사용자 브라우저 식별 정보를 반환.)

 


 

1.

  • navigator 객체에 속하는 읽기전용 (read-only) 속성임.
  • 반환값에는 브라우저의 (이름/버전/플랫폼 등) 정보가 포함됨.
  • 웹 사양에선 브라우저가 가능한 적은 헤더 정보를 제공해야 한다 제안.
  • 이 속성이 향후 브라우저에서 변경되지 않을 거라고 여기지 말 것.

 

2. MDN navigator.userAgent 매뉴얼 보기

https://developer.mozilla.org/en-US/docs/Web/API/Navigator/userAgent

 

 

navigator.userAgent 구문

 

navigator.userAgent

 

 

navigator.userAgent 예제 - navigator 관련 모든 속성 표시

 

<div id="demo"></div>


<script>

let text = "<p>브라우저 코드명: " + navigator.appCodeName + "</p>" +

"<p>브라우저 이름: " + navigator.appName + "</p>" +

"<p>브라우저 버전: " + navigator.appVersion + "</p>" +

"<p>쿠기 활성화 여부: " + navigator.cookieEnabled + "</p>" +

"<p>브라우저 언어: " + navigator.language + "</p>" +

"<p>브라우저 온라인 여부: " + navigator.onLine + "</p>" +

"<p>플랫폼: " + navigator.platform + "</p>" +

"<p>브라우저 식별 정보: " + navigator.userAgent + "</p>";


document.getElementById("demo").innerHTML = text;

</script>

 

결과보기

 

navigator.userAgent 예제 - 브라우저별 분기 조건문

 

var agent = navigator.userAgent.toLowerCase();


if(agent.indexOf("chrome") != -1) {

    console.log("크롬");

}

if(agent.indexOf("safari") != -1) {

    console.log("사파리");

}

if(agent.indexOf("firefox") != -1) {

    console.log("파이어폭스");

}

if(agent.indexOf("Edge") != -1) {

    console.log("Edge");

}


// 모든 IE 브라우저 체크 (IE 11 포함)

if((navigator.appName == 'Netscape' && agent.indexOf('trident') != -1) || (agent.indexOf("msie") != -1)) {

     console.log("IE (O)");

} else {

     console.log("IE (X)");

}

 

(221213) https://mylife365.tistory.com/503


분류 제목
Window_Navigator JS - navigator.userAgent 속성 - 사용자 브라우저 정보 반환 (= navigator.us…
Window_Navigator JS - javaEnabled() 메서드 -
Window_Navigator JS - taintEnabled() 메서드 - JS1.2 버전에서 폐기완료. 브라우저에 데이터오염 있는지 확…
Window_Screen JS - availHeight 속성 ★ - 화면높이 (※ 작업표시줄 제외)
Window_Screen JS - availWidth 속성 ★ - 화면너비 (※ 작업표시줄 제외)
Window_Screen JS - colorDepth 속성 - 이미지 표시 위한 색상표 비트 심도를 픽셀 단위로 반환
Window_Screen JS - height 속성 ★ - 객체 높이 ※ screen.height: 화면 높이 (※ 작업표시줄 포함)
Window_Screen JS - pixelDepth 속성 - 방문자 화면의 색상해상도 (= 픽셀 당 비트 수) 반환 (IE10 이상…
Window_Screen JS - screen.width 속성 ★ - 스크린너비 (= 화면너비 = screen.width속성 = 스크…
DOM_Style JS - alignContent 속성(C) - 플렉스항목 세로정렬 (= alignContent속성 = 얼라인…
DOM_Style JS - alignItems 속성(C) - 플렉스아이템의 세로정렬방법 지정 (예: 상단정렬/하단정렬/균등배분…
DOM_Style JS - alignSelf 속성(I) - (플렉스아이템 수직정렬. 아이템 자체에 사용. align-self속…
DOM_Style JS - animation 속성 ★ - 애니일체 (= 움직임효과 = 이동효과 = 애니일괄 = 애니효과 = 애…
DOM_Style JS - animationDelay 속성 - 애니지연시간 (= animationDelay속성 = 애니메이션딜…
DOM_Style JS - animationDirection 속성 - 애니방향 (= 움직임방향 = 애니메이션디렉션속성, IE1…
DOM_Style JS - animationDuration 속성 - 애니지속시간 (= 애니완료소요시간 = 움직임완료소요시간 =…
DOM_Style JS - animationFillMode 속성 - 애니 미작동 스타일 (= 애니작동안할때 스타일 = 애니메이…
DOM_Style JS - animationIterationCount 속성 -애니메이션 반복횟수 설정/반환
DOM_Style JS - animationName 속성 - 키프레임명 (= 키프레임이름 = 애니이름 = 애니명 = 애니메이션…
DOM_Style JS - animationTimingFunction 속성 - 애니속도변화 (= 애니속도변경 = 애니속도곡선 …
42/67
목록
찾아주셔서 감사합니다. Since 2012