navigator 객체
사용자의 접속 환경 등을 감지할 수 있음. 버전 등도 감지 가능
appName() : 브라우저 이름을 얻어옴.
geolocation.getCurrentPosition() : 현재 위치 정보를 얻어옴. 브라우저가 접속된 위치정보
+)appName : "Netscape" =초창기 브라우저가 이 회사에서 만들어졌음
+)userAgent:"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
어플리케이션 버전, css렌더링 엔진, 어플리케이션 정보
geolocation.getCurrentPosition(함수,함수);
<!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>Document</title>
</head>
<body>
<script>
//사용자의 접속환경을 userAgent속성으로 확인할 수 있음
var userAgent=navigator.userAgent.toLowerCase();
// console.log(userAgent);
// console.log(userAgent.lastIndexOf('edg'));//못찾으면 -1 반환
if(userAgent.lastIndexOf("edg")!=-1){//찾았으면
console.log("엣지");
}else if(userAgent.lastIndexOf("chrome")!=-1){
console.log("크롬");
}else if(userAgent.lastIndexOf("firefox")!=-1){
console.log("파이어폭스");
}else if(userAgent.lastIndexOf("whale")!=-1){
console.log("웨일");
}else if(userAgent.lastIndexOf("chrome")!=-1){
console.log("엣지");
}
</script>
</body>
</html>
userAgent가 "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"로 나옴. 크롬으로 실행해서 안에 Chrome이 있으므로 콘솔창에 크롬이 출력된다.
'JS' 카테고리의 다른 글
230105 JS 쿠키-생성과 사용 (1) | 2023.01.05 |
---|---|
230105 JS navigator객체2, 콜백함수 (0) | 2023.01.05 |
230105 JS history객체 (0) | 2023.01.05 |
230105 JS location객체 (0) | 2023.01.05 |
230104 JS window객체와 애니메이션 실습 (0) | 2023.01.04 |