BoxLang 🚀 A New JVM Dynamic Language Learn More...

MobileDetect

v2.2.0 Projects

Mobile Detect

Motto: "Every business should have a mobile detection script to detect mobile readers."

MobileDetect is a CFC port of the Mobile_Detect PHP Library which was originally authored by Victor Stanciu [email protected] and is now currently authored by Serban Ghita [email protected] and Nick Ilyin [email protected].

Their project is on GitHub and can be seen here:
https://github.com/serbanghita/Mobile-Detect

The site for their project is:
http://mobiledetect.net/

I've used this library in various PHP projects and decided to port it over to be able to use in my ColdFusion Projects.

The library is used for detecting mobile devices (including tablets). It uses the UserAgent string combined with specific HTTP headers to detect the mobile environment.

This current version is based on their 2.8.22 release

###Supported Versions This CFC is script based and written using some of the new language enhancements in ColdFusion 11. Although making it compatible with earlier versions can be done by replacing the code using the Member Functions for their previous equivalent global functions.

###Differences from PHP Library The one main difference is the "is" function. As it is a reserved word in ColdFusion I had to chage it to "_is". Below are some examples of how to use.

<cfscript>
MobileDetect = new MobileDetect();

// Basic Detection
MobileDetect.isMobile();
MobileDetect.isTablet();

// Magic Methods
MobileDetect.isIPhone();
MobileDetect.isSamsung();
// [...]

// Alternative to magic methods.
MobileDetect._is('iphone');

// Additional match method.
MobileDetect.match('regex.*here');

// Browser grade method.
MobileDetect.mobileGrade();

// Overwrite UserAgent or HttpHeaders to use
MobileDetect.setUserAgent(userAgent); // string
MobileDetect.setHttpHeaders(httpHeaders); // struct
</cfscript>

This should help you familiarize with how the CFC works. You can compare the examples above to their Wiki Page and get even more examples on how to use.

https://github.com/serbanghita/Mobile-Detect/wiki/Code-examples

You can also run the examples included by executing in your local ColdFusion install or simply use CommandBox to run and execute.

After installing CommandBox, browse to the directory of this repo and type the following and then browse to the examples folder:

box server start

Examples are also available here
http://www.fusedevelopments.com/examples/mobile-detect/

$ box install mobiledetect

No collaborators yet.
     
  • {{ getFullDate("2016-09-08T00:41:00Z") }}
  • {{ getFullDate("2019-06-12T14:12:33Z") }}
  • 2,686
  • 101