Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

Detect mobile device or browser and act accordingly

MobileDetect class detects if current visitors uses a mobile device to access the page. Additionally it tries to detect device/browser type and helps you act accordingly.

Package contains MobileDetect.js and MobileDetect.packed.js (packed javascript)and two example files: simple_example.html and example.html to demonstrate class functionality.

Contents

Download

Example codes

var md = new MobileDetect();
md.addEventListener("iphone", forIOS);
md.addEventListener("ipad", forIOS);
md.addEventListener("ipod", forIOS);
md.addEventListener("itunes", forIOS);
md.addEventListener("android", forAndroid);
md.addEventListener("samsung", forSamsung);
md.addEventListener("kindle", forKindle);

Examples in action

Example scripts provided with package in action:

Method list

Constructor

Back to method list

Method namenew MobileDetect(callback);
DescriptionCreate an instance of MobildeDetect
Input parameters

function callback - function that receives true if used device is mobile and false if it's not

Example input
var md = new MobileDetect(function(mobile){
	alert(mobile);
});

Add event for specific device/browser

Back to method list

Method nameaddEventListener(device, callback)
DescriptionAds callback function for specific device/browser types
Input parameters

string device - device/browser type for which to set a callback. Possible values:

  • alcatel
  • android
  • au-mic
  • audiovox
  • avantgo
  • blackberry
  • blazer
  • bolt
  • cldc-
  • cricket
  • danger
  • ddi
  • docomo
  • epoc
  • ericsson
  • ericy
  • htc
  • ipad
  • ipaq
  • iphone
  • ipod
  • itunes
  • j2me
  • kddi
  • kindle
  • netfront
  • nintendo
  • nitro
  • nokia
  • midp-
  • minimo
  • mobile
  • mot
  • opera mini
  • opera mobi
  • palmos
  • palmsource
  • panasonic
  • philips
  • pie
  • pocketpc
  • portalmmm
  • rim
  • rover
  • samsung
  • sanyo
  • series60
  • sharp
  • sie-
  • smartphone
  • sony
  • symbian
  • tablet
  • tear
  • up.browser
  • up.link
  • vodafone
  • wap
  • windows ce
  • windows phone
  • wp7
  • xiino

function callback - function to call if visitor uses provided device/browser

Check if device is mobile

Back to method list

Method nameisMobile()
DescriptionCheck if visitor uses a mobile device

Get type of device/browser

Back to method list

Method namegetMobile()
DescriptionGet mobilde device/browser type as discussed in addEventListener section

Latest changes

None for now


You may also be interested in:

Powered by BlogAlike.com

blog comments powered by Disqus