Giter VIP home page Giter VIP logo

devicedetector's Introduction

Device detector (client-side device detecting)

A simple JavaScript object to detect if you are running on a desktop, tablet or mobile device. It inspects the navigator.userAgent string to find out which device you are using.

There are numorous scripts out there that do the same, though I've always found they are somewhat incomplete. For example, none of them took into account the emerging fennect (firefox OS) device.

Usage

Include the script, or copy/paste it in your own project:

<script type="text/javascript" src="https://raw.githubusercontent.com/PoeHaH/devicedetector/master/devicedetector-min.js"/>

You're now ready to access the object:

if(deviceDetector.device == 'desktop')
  // You're on a desktop.
else{
  if(deviceDetector.device == 'tablet')
    // You're on a tablet.
  else
    // You're on a phone.
}

Properties

  • deviceDetector.device contains the device you're browsing on. desktop, tablet or phone.
  • deviceDetector.isMobile is true if the device is a phone or tablet. False otherwise.
  • deviceDetector.userAgent contains the user agent string the check is performed against.

Functions

  • deviceDetector.detect(userAgent) allows you to detect based on a given user agent string. If the argument is not supplied, navigator.userAgent is used.

##Tests

In the tests folder, you can find .txt files with 300 random user agent strings per device. This can be used to test with the supplied index.html.

The strings for the txt files are coming from:

###results

Phones & desktops are discoverred without issue. Tablets are detected correctly for 98%.

devicedetector's People

Contributors

poehah avatar

Watchers

yiliaofan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.