본문 바로가기
개발일지

js로 실행장치 알아내기

by 케이오스 2020. 5. 12.

react 작업중에 pc 일때와 mobile 일때 정렬이 다를 때가 있어서 찾아보다가 발견함.

 

console.log("=======navigator.userAgent========\n"navigator.userAgenttypeof navigator.userAgent, /android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase()));

if (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase())) {
어쩌고 저쩌고
}

mobile 아닐 때

 

mobile 일때

확실히 .toLowerCase() 방식이 편한듯..