프론트엔드 개발 놀이터/Javascript
홈페이지 접속시 자동으로 모바일로 이동
내나라
2020. 12. 2. 22:44
아래와 같이 2가지 방법이 있습니다.
뭐가 더 좋은지는 잘 모르겠습니다.
function isPC() {
return /win16|win32|win64|mac|macintel/i.test(navigator.userAgent);
}
if( ! isPC() ) { //alert('mobile 접속')
location.href = '/m/';
}
function isMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}
if( isMobile() ) { //alert('mobile 접속')
location.href = '/m/';
}