Contents

조회 수 3788 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

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/


?

  1. [js] Javascript로 만든 포트리스 (2010)

    Date2017.03.03 CategoryDevelop Byhooni Views5473
    Read More
  2. [linux] resolv.con 초기화 되는 문제

    Date2014.04.05 CategorySystem/OS Byhooni Views5454
    Read More
  3. [ios] AES256 알고리즘을 이용해 데이터 암호화/복호화 방법

    Date2015.07.21 CategoryDevelop Byhooni Views5453
    Read More
  4. [android] 초간단 얼럿 (AlertDialog)

    Date2016.10.21 CategoryDevelop Byhooni Views5444
    Read More
  5. [mysql] 중복데이터 삭제하는 초간단 쿼리

    Date2017.11.22 CategoryDatabase Byhooni Views5408
    Read More
  6. [ios] iOS 7 이상 UIBarButtonItem 여백

    Date2014.03.27 CategoryDevelop Byhooni Views5379
    Read More
  7. What is difference between Get, Post, Put and Delete?

    Date2018.02.28 CategoryDevelop Byhooni Views5335
    Read More
  8. [ios] 앱딜리게이트 라이프사이클 (AppDelegate Lifecycle)

    Date2014.05.09 CategoryDevelop Byhooni Views5334
    Read More
  9. [linux] CentOS Apache Httpd에 https 적용

    Date2014.03.05 CategorySystem/OS Byhooni Views5327
    Read More
  10. [ios] URL Scheme 이용하여 앱 설치 확인

    Date2014.03.10 CategoryDevelop Byhooni Views5281
    Read More
  11. [ios] iOS 의 인앱구매 소개

    Date2014.04.29 CategoryDevelop Byhooni Views5251
    Read More
  12. [ios][swift] 초간단 TableView 샘플

    Date2016.06.27 CategoryDevelop Byhooni Views5215
    Read More
Board Pagination Prev 1 ... 72 73 74 75 76 77 78 79 80 81 ... 99 Next
/ 99