본문 바로가기

JQuery-js-css

모바일 web에서 안드로이드, iOS 구분하기

 




  var currentOS;

  $(document).ready(function(){

 

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

 

  if (mobile) {  //navigator.userAgent에 /iphone|ipad|ipod|android 의 단어포함이 true 일때

  // 유저에이전트를 불러와서 OS를 구분합니다.

  var userAgent = navigator.userAgent.toLowerCase();

  if (userAgent.search("android") > -1)

  currentOS = "android";

  else if ((userAgent.search("iphone") > -1) || (userAgent.search("ipod") > -1)

  || (userAgent.search("ipad") > -1))

  currentOS = "ios";

 

  } else {

  // 모바일이 아닐 때

  currentOS = "nomobile";

  }

 

  });