WebPublisher/JavaScript & jQuery
[javaScript] navigator.userAgent 사용해 사용자 브라우저 체크하기
amanda
2025. 11. 14. 10:11
자바스크립트로 사용자 브라우저 체크하기
navigator.userAgent 사용
indexOf()를 활용하는데 > -1 도 되고 != 1 도 가능
const browserCheck = () => {
const userAgent = navigator.userAgent.toLowerCase();
if (userAgent.indexOf("edge") > -1){
return "edge";
} else if (userAgent.indexOf("whale") > -1){
return "whale";
} else if (userAgent.indexOf("chrome") > -1){
return "chrome";
} else if (userAgent.indexOf("firefox") > -1){
return "firefox";
} else {
return "msie";
}
}
요건 userAgent로 사용자 디바이스 체크하는 방법
const agentCheck = () => {
var agent = navigator.userAgent.toLowerCase();
if (agent.indexOf("app") != -1) {
if (agent.indexOf("android") != -1) {
return "AND";
} else if (agent.indexOf("iphone") != 1 || agent.indexOf("ipad") != 1 || agent.indexOf("ipod") != -1) {
return "IOS";
}
} else {
return "WEB";
}
}
userAgent 변경하는 방법
기본으로는 읽기 전용이라 변경 안되는 값이지만 크롬 브라우저에서 가능
https://guiyomi.tistory.com/117
Javascript - navigator.userAgent이란? + 값 변경하는 법
window 전역 객체 내에는 location, navigator, web storage 등 다양한 프로퍼티가 존재한다. var 키워드로 선언된 전역 변수 또한 window 전역 객체의 프로퍼티로 접근이 가능하다. window 전역 객체는 식별자 wi
guiyomi.tistory.com