Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 애니메이션
- input
- IntersectionObserver
- scroll
- Push
- ES6
- json
- 문자열
- async
- object
- This
- dom
- array
- Promise
- 이벤트
- 모듈
- video
- ios
- 배열
- slice
- 스크롤
- ajax
- animation
- 비동기
- event
- Flex
- 고차함수
- 클로저
- 이벤트 위임
- 이벤트 루프
Archives
- Today
- Total
FEDev Story
How to detect browser in JavaScript [Chrome, Firefox, Safari, Opera, Edge , MS IE]? 본문
Web.Dev
How to detect browser in JavaScript [Chrome, Firefox, Safari, Opera, Edge , MS IE]?
지구별72 2021. 12. 19. 16:38https://codepedia.info/detect-browser-in-javascript
Approach 1: JavaScript code to detect browser name using userAgent.match
function fnBrowserDetect(){
let userAgent = navigator.userAgent;
let browserName;
if(userAgent.match(/chrome|chromium|crios/i)){
browserName = "chrome";
}else if(userAgent.match(/firefox|fxios/i)){
browserName = "firefox";
} else if(userAgent.match(/safari/i)){
browserName = "safari";
}else if(userAgent.match(/opr\//i)){
browserName = "opera";
} else if(userAgent.match(/edg/i)){
browserName = "edge";
}else{
browserName="No browser detection";
}
document.querySelector("h1").innerText="You are using "+ browserName +" browser";
}
Approach 2: JavaScript code to detect browser using userAgent.IndexOf
var browserName = (function (agent) {
switch (true) {
case agent.indexOf("edge") > -1: return "MS Edge";
case agent.indexOf("edg/") > -1: return "Edge ( chromium based)";
case agent.indexOf("opr") > -1 && !!window.opr: return "Opera";
case agent.indexOf("chrome") > -1 && !!window.chrome: return "Chrome";
case agent.indexOf("trident") > -1: return "MS IE";
case agent.indexOf("firefox") > -1: return "Mozilla Firefox";
case agent.indexOf("safari") > -1: return "Safari";
default: return "other";
}
})(window.navigator.userAgent.toLowerCase());
document.querySelector("h1").innerText="You are using "+ browserName +" browser";
'Web.Dev' 카테고리의 다른 글
video 넣는 방법 (0) | 2021.12.23 |
---|---|
playsinline - iOS비디오정책 (0) | 2021.12.23 |
How to hide HTML5 video controls completely (0) | 2021.12.16 |
탑 스크롤 애니메이션 구현하기 (0) | 2021.09.09 |
페이지 로딩 속도 측정 (0) | 2021.08.27 |
Comments