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 firstname.lastname@example.org and is now currently authored by Serban Ghita email@example.com and Nick Ilyin firstname.lastname@example.org.
Their project is on GitHub and can be seen here:
The site for their project is:
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.
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