Search code examples
mobilecoldfusiondetection

mobile detection for coldfusion


Is there a way to detection if a user is on a mobile device using just coldfusion only?

  1. I'm not doing a mobile redirect.
  2. I am using CSS media queries to change the layout to fit screen width.
  3. I just want to do a simple if mobile render this information else render this information instead to parts of the site not the whole thing. (ex: if mobile [show jquery animation] else show [link])
  4. I don't want to waste time rendering both if only to do a display none to the info not going to be shown anyways.
  5. No javascript mobile detection (people might have javascript off on their browsers)

Solution

  • I wrote a blog entry about this very thing!

    http://www.mccran.co.uk/index.cfm/2010/6/4/Simple-Coldfusion-script-to-detect-if-a-user-is-on-a-Mobile-platform

    <cfif findNoCase('Android', cgi.http_user_agent,1)>
    <!--- relocate to Android version of the mobile site --->
    <cflocation url="android/">
    <cfelseif findNoCase('iPhone', cgi.http_user_agent,1)>
    <!--- relocate to iphone version of the mobile site --->
    <cflocation url="iphone/">
    </cfif>
    

    You can easily detect the browser from the user agent string. Tho as I've experienced recently browsers like chrome will allow you to change your user agent string:

    http://www.mccran.co.uk/index.cfm/2011/9/25/Samsung-Galaxy-Tab-101-Switching-your-browser-from-mobile-view