Views 2449 Votes 0 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

In these modern days mobile devices are really very common. So every programmer should be aware of their applications compatibility with mobile devices. For that the applications must have the functionality to Detect Mobile Devices. Using JavaScript or jQuery it is really very easy to Detect Mobile Devices.

How to Detect Mobile Devices with jQuery or JavaScript

There are many ways to detect Mobile Devices. In this lesson I will share some tricks on How to Detect Mobile Devices with Javascript or jQuery. So lets get started.

1. Using a JavaScript Function to Detect Mobile Devices

This example shows a function which will return if your device is Mobile or not.

var isMobile = {
    Android: function() {
        return navigator.userAgent.match(/Android/i);
    },
    BlackBerry: function() {
        return navigator.userAgent.match(/BlackBerry/i);
    },
    iOS: function() {
        return navigator.userAgent.match(/iPhone|iPad|iPod/i);
    },
    Opera: function() {
        return navigator.userAgent.match(/Opera Mini/i);
    },
    Windows: function() {
        return navigator.userAgent.match(/IEMobile/i);
    },
    any: function() {
        return (isMobile.Android() || isMobile.BlackBerry() ||
            isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
    }
};


Now you can check if its a Mobile Device by using this function:

if(isMobile.any()) {
   alert("This is a Mobile Device");
}

If this is a Mobile Device then an alertbox will popup.

2. Another JavaScript trick to Detect Mobile Devices

This simple code will check if the current device is a mobile and you can put your tasks inside the if statement when it detects a Mobile Device.

if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|
    Opera Mini/i.test(navigator.userAgent) )
{
    // tasks to do if it is a Mobile Device
    alert("Mobile Detected");
}

3. Using jQuery or any other popular language

Detect Mobile Browser has a great collection of scripts to Detect Mobile Devices. You can get Mobile Device detection scripts for Apache, ASP, ASP.NET, ColdFusion, C#, IIS, JSP, JavaScript, jQuery, Lasso, nginx, node.js, PHP, Perl, Python, Rails etc. The script list is pretty much big so don’t hesitate to explore this with your favorite language script.

There is also a JavaScript Library named isMobile. It is really fast and very easy to use. So you can give it a try. 

Hope now you know how to Detect Mobile Devices.


[출처] http://jstricks.com/detect-mobile-devices-javascript-jquery/

?

List of Articles
No. Category Subject Author Date Views
533 Develop [android] 디바이스(시뮬레이터) hosts 파일 수정하기 hooni 2013.04.23 31066
532 Develop [android] 개발 환경 세팅 따라하기 ㅋㅋ file hooni 2013.04.23 40396
531 Develop [ios] 아이폰용 앱 오픈 소스들 hooni 2013.04.23 466701
530 Develop [doc] Json Framework 설치와 사용 file hooni 2013.04.23 21916
529 Etc 스마트폰 보안 해외 발생 사례~ file hooni 2013.04.23 24936
528 PPT [doc] 정보보호이론 강의자료 (중앙대꺼..) 2 file hooni 2013.04.23 22811
527 Develop [ios] UDID와 UUID (디바이스의 Unique Identifier) file hooni 2013.04.23 27335
526 Develop [ios] 푸시알림(APNS)에 대한 php 라이브러리 ㅋㅋ hooni 2013.04.23 16632
525 Develop [winmobile] 윈도우 모바일 간단한 테스트 코드 ㅋㅋ file hooni 2013.04.23 17083
524 Develop [ios] iOS 4.0 beta 에서 3.1.3으로 다운그레이드 하는 법 file hooni 2013.04.23 37497
523 Develop [c] 메시지큐(Message Queue) 설명.. (joinc) hooni 2013.04.23 14273
522 Develop [android] 단일 Thread 환경의 안드로이드에서 Handler를 사용 file hooni 2013.04.23 26493
521 Develop [android] 점심 해결 앱 소스 코드 ㅋㅋ file hooni 2013.04.23 76396
520 Develop [ios] 한샘 카달로그 앱 소스 (아이폰용) secret hooni 2013.04.23 10922
519 Develop [android] 화면 전환(가로/세로)시 설정 hooni 2013.04.23 43371
518 Develop [android] 멀티터치(Multi touch) 부분 구현 ㅋㅋ file hooni 2013.04.23 27415
Board Pagination Prev 1 ... 39 40 41 42 43 ... 74 Next
/ 74