프로그래밍/JAVASCRIPT
[JS, JAVASCRIPT] 모바일기기로 접속했을 경우, 모바일 페이지로 이동하기
소 아
2020. 8. 10. 18:39
모바일 디바이스를 감지해 모바일 페이지로 리다이렉트 되는 스크립트
둘 중 하나 쓰면 된당.
1.
var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windowssce|palm/i.test(navigator.userAgent.toLowerCase()));
if (mobile) {
window.location.href = "이동할 경로";
}
2.
var UserAgent = navigator.userAgent;
if (UserAgent.match(/iPhone|iPod|Android|Windows CE|BlackBerry|Symbian|Windows Phone|webOS|Opera Mini|Opera Mobi|POLARIS|IEMobile|lgtelecom|nokia|SonyEricsson/i) != null || UserAgent.match(/LG|SAMSUNG|Samsung/) != null) {
location.href = "모바일 경로";
} else {
alert("Web");
}