For the complete experience, please enable JavaScript in your browser. Thank you!

  • Creative Cloud
  • Photoshop
  • Illustrator
  • InDesign
  • Premiere Pro
  • After Effects
  • Lightroom
  • See all
  • See plans for: businesses photographers students
  • Document Cloud
  • Acrobat DC
  • eSign
  • Stock
  • Elements
  • Marketing Cloud
  • Analytics
  • Audience Manager
  • Campaign
  • Experience Manager
  • Media Optimizer
  • Target
  • See all
  • Acrobat Reader DC
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player
  • All products
  • Creative Cloud
  • Individuals
  • Photographers
  • Students and Teachers
  • Business
  • Schools and Universities
  • Marketing Cloud
  • Document Cloud
  • Stock
  • Elements
  • All products
  • Get Support
    Find answers quickly. Contact us if you need to.
    Start now >
  • Learn the apps
    Get started or learn new ways to work.
    Learn now >
  • Ask the community
    Post questions and get answers from experts.
    Start now >
    • About Us
    • Careers At Adobe
    • Investor Relations
    • Privacy  |  Security
    • Corporate Responsibility
    • Customer Showcase
    • Events
    • Contact Us
News
    • 3/22/2016
      Adobe Summit 2016: Are You An Experience Business?
    • 3/22/2016
      Adobe Announces Cross-Device Co-op to Enable People-Based Marketing
    • 3/22/2016
      Adobe and comScore Advance Digital TV and Ad Measurement
    • 3/22/2016
      Adobe Marketing Cloud Redefines TV Experience
ColdFusion Help / 

Device Detection

Adobe Community Help


Applies to

  • ColdFusion

Contact support

 
By clicking Submit, you accept the Adobe Terms of Use.
 

Detecting the device characteristics

The device detection feature of CFML allows you to identify the device properties and characteristics, which can be used to determine the best content, layout, mark-up or application to serve to the given   device.

These characteristics include screen size, browser type and version, media support, and the level of support for CSS, HTML, and JavaScript.

For getting the device features and capabilities, you need to specify an attribute detectDevice in the <cfclientsettings> tag and set it to true:

<cfclientsettings detectDevice=true />

If the detectDevice attribute is set to true, ColdFusion automatically detects the features and capabilities of the device (width, height, and orientation) on which the application is running.

Note: If detectDevice is set to false, all <div> elements need to be defined before the <cfclient> block.

Supported device detection features

The following example shows the usage of the device detection feature:

<cfClientSettings detectDevice=true />


<cfclient>


<cffunction access="public" name="showcanvassupport" returntype="void" >
<cfset document.getElementById('canvas').innerHTML=cfclient.properties.canvas>

</cffunction>


</cfclient>


Canvas support -<b id="canvas"></b><br>
<button onclick="invokeCFClientFunction('showcanvassupport',null)">
Show canvas support
</button>

In the above example, we are trying to find if the device supports HTML5 Canvas.  cfclient.properties.canvas returns a boolean value indicating the support for the HTML5 Canvas property.

ColdFusion Server internally uses Modernizer JavaScript library (version 2.6.2) for the device detection feature.

The following table lists the supported device features with example usage:

Features

Syntax

Touch Events

cfclient.properties.touch

Canvas Text

cfclient.properties.canvastext

Canvas

cfclient.properties.canvas

Geolocation

cfclient.properties.geolocation

Web Sockets

cfclient.properties.websockets

Drag ‘n Drop

cfclient.properties.draganddrop

History

cfclient.properties.history

applicationCache

cfclient.properties.applicationcache

localStorage

cfclient.properties.localstorage

Width

cfclient.properties.width

Height

cfclient.properties.height

Device Width

cfclient.properties.deviceWidth

Device Height

cfclient.properties.deviceHeight

Orientation

cfclient.properties.orientation

Device Group Name

cfclient.properties.deviceGroupName

Device Group Descriptions

cfclient.properties.deviceGroupDescription

CSS Animations

cfclient.properties.cssanimations

CSS Columns

cfclient.properties.csscolumns

CSS Generated Content

Cfclient.properties.generatedcontent

CSS Gradients

cfclient.properties.cssgradients

CSS Reflections

cfclient.properties.cssreflections

CSS 2D Transforms

cfclient.properties.csstransforms

CSS 3D Transforms

cfclient.properties.csstransforms3d

CSS Transitions

cfclient.properties.csstransitions

Audio

cfclient.properties.audio

Video

cfclient.properties.video

Hash Change

cfclient.properties.hashchange

IndexedDB

cfclient.properties.indexeddb

Input Attributes

cfclient.properties.input.* (* refers to attributes for input elements. For possible values, see the Modernizr documentation)

Input Types

cfclient.properties.inputtypes.* (* refers to input type attributes. For possible values, see the Modernizr documentation)

Post Message

cfclient.properties.postmessage

Session Storage

cfclient.properties.sessionstorage

Web Workers

cfclient.properties.webworkers

Web SQL Database

cfclient.properties.websqldatabase

 

For the description on all above mentioned features, see the Modernizr documentation.

Using media queries

Media queries allow you to apply changes to the page design based on the viewing size and capability of the device on which your content is displayed. A media query consists of one or more logical expressions formed using the detected device data that checks for certain conditions of media feature and based on the result of this expression we can change the layout of the page dynamically.

If you are building a mobile application, you can easily detect the characteristics of the device and customize the layout just for that device as shown in the following example:

<cfclientsettings detectDevice=true />
<cfclient>
<cfif cfclient.properties.width lte 480 >
<cfinclude template=" phone.css ">

<cfelseif cfclient.properties.width gte 480 AND cfclient.properties.width lte
760>
<cfinclude template=" tablet.css ">

<cfelse>
<cfinclude template=" desktop.css ">

</cfif>
</cfclient>

In the above example, the web page is customized for different devices based on their screen sizes.

Handling orientation changes

For handling the device orientation changes, you can register a listener using the addOrientationListener() function:

<cfclientsettings detectDevice=true />
<cfclient>
<cfoutput>
Orientation : <b id="orientationId"></b><br>
Width : <b id="width"></b><br>
Height : <b id="height"></b><br>
</cfoutput>
<!--- Adding the orientation handler here. After adding
the handler, the handler will be invoked whenever there
is an orientation change. --->


<cfset cfclient.addOrientationListener(orientationHandler)>



<cffunction access="public" name="orientationHandler"
returntype="void" >
<cfargument name="orientationString" type="string">
<!--- The orientation (landscape/portrait) will be
passed as an argument to the handler. You can also get
the orientation value from cfclient. --->
</cffunction>
</cfclient>

In the above example, addOrientationListener function is used to register a listener that monitors the orientation of the device (landscape or portrait). When the orientation of the device changes, an orientationHandler call back function is invoked.

You can use the removeOrientationListener to un-register the listener:

<cffunction access="public" name="removeorientationhandler"
returntype="void" >
<cfset cfclient.removeOrientationListener(orientationhandler)>
</cffunction>

You can also add multiple listeners:

<cfset cfclient.addOrientationListener(orientationHandler1)>
<cfset cfclient.addOrientationListener(orientationHandler2)>

When the device orientation changes, all the registered listener functions are invoked.

Handling window resizing events

For handling the window resizing events, you can register a listener using the addResizeListener() function:

<cfclientsettings detectDevice=true />
<cfclient>
<cfoutput>
Width :<b id="width"></b><br>
Height :<b id="height"></b><br>
Device width :<b id="devicewidth"></b><br>
Device height :<b id="deviceheight"></b><br>
</cfoutput>
<!--- Adding the resize handler here.
After adding the handler, the handler will be
invoked whenever there is a browser
resize. --->


<cfset cfclient.addResizeListener(resizehandler)>

<cffunction access="public" name="resizehandler"
returntype="void" >
<cfargument name="width" type="string">
<cfargument name="height" type="string">
<cfset document.getElementById('width').innerHTML=width>
<cfset document.getElementById('height').innerHTML=height>
<cfset document.getElementById('devicewidth').innerHTML=cfclient.properties.deviceWidth>
<cfset document.getElementById('deviceheight').innerHTML=cfclient.properties.deviceHeight>
</cffunction>
</cfclient>

You can also add multiple listeners:

<cfset cfclient.addResizeListener(resizeHandler1)>
<cfset cfclient.addResizeListener(resizeHandler2)>

When there is a change in window size  all the registered resize listener functions are invoked. You can use removeResizeListener() to un-register the handlers.

<cffunction access="public" name="removeresizehandler"
returntype="void" >
<cfset cfclient.removeResizeListener(resizeHandler)>
</cffunction>

Setting device timeout

In the <cfclientsettings> tag, an attribute called deviceTimeOut can be specified. The default value of deviceTimeout is 10 secs. When enableDeviceApi or detectDevice is set as true, the deviceTimeOut value will be honored. Time will be provided for the required plugins to be loaded. After the specified time, an exception will be thrown.

<cfclientsettings detectDevice=true deviceTimeOut="30" />

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy

Choose your region United States (Change)   Products   Downloads   Learn & Support   Company
Choose your region Close

Americas

Europe, Middle East and Africa

Asia Pacific

  • Brasil
  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Cyprus - English
  • Česká republika
  • Danmark
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Greece - English
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • Malta - English
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • Southeast Asia (Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam) - English
  • 台灣

Commonwealth of Independent States

  • Includes Armenia, Azerbaijan, Belarus, Georgia, Moldova, Kazakhstan, Kyrgyzstan, Tajikistan, Turkmenistan, Ukraine, Uzbekistan

Copyright © 2016 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

AdChoices