JAVASCRIPT PC MOBILE 구분/ 브라우저 구분
var device = "pc";
var browserName = undefined;
var userAgent = navigator.userAgent.toLowerCase();
var userAgentName = navigator.appName;
var mobileDevice;
var mobilePhones = new Array('iphone','ipod','android','blackberry','windows ce','nokia','webos',
'opera mini','sonyericsson','opera mobi','iemobile');
/* pc, mobile 확인 */
for(var i=0;i<mobilePhones.length;i++) {
if(userAgent.indexOf(mobilePhones[i]) != -1){
device = "mobile";
}
}
/* mobile device name 확인 */
for(var txt in mobilePhones){
if(userAgent.match(mobilePhones[txt]) != null){
mobileDevice = mobilePhones[txt];
break;
}
}
/* browser name 확인 */
switch (true) {
case /trident|msie/.test(userAgent):
browserName = 'ie';
break;
// IE 12(edge)
case /edge/.test(userAgent):
browserName = 'edge';
break;
case /chrome/.test(userAgent):
browserName = 'chrome';
break;
case /safari/.test(userAgent):
browserName = 'safari';
break;
case /firefox/.test(userAgent):
browserName = 'firefox';
break;
case /opera/.test(userAgent):
browserName = 'opera';
break;
default:
browserName = 'unknown';
}
console.log("browser_name : " + browserName);
console.log("device : " + device);