모바일 분기

보현·2020년 12월 24일
0

JavaScript

목록 보기
2/3

모바일 분기

자바스크립트로 모바일 기기와 비모바일을 구분한다.

var mobile = (/iphone|ipad|ipod|android/i.test(navigator.userAgent.toLowerCase()));

if (mobile) { 
  //모바일 처리
}else{
  //비 모바일 처리
}

iOS와 안드로이드 분기

var varUA = navigator.userAgent.toLowerCase(); //userAgent 값 얻기

if ( varUA.indexOf('android') > -1) {
  //안드로이드
  return "android";
} else if ( varUA.indexOf("iphone") > -1||varUA.indexOf("ipad") > -1||varUA.indexOf("ipod") > -1 ) {
  //IOS
  return "ios";
} else {
  //아이폰, 안드로이드 외
  return "other";
}
profile
실천하는 보현이가 되자, 제발

0개의 댓글