5 Replies Latest reply on Jan 26, 2009 8:03 AM by Adrian_Hope-Bailie

    Page Redirects For Mobile Devices

    Bearded Coffee Monkey
      I have a project where we have some web based pages that are to be accessed by mobile devices. Unfourtnately, we are getting support calls and most are from people accessing the main page though a normal, desktop browser.

      Is there a way in CF to sort out whether the person is visiting from a mobile device browser or a desktop browser and redirect the page accordingly?

        • 1. Re: Page Redirects For Mobile Devices
          jdeline Level 1
          Yes. Check the CGI.HTTP_USER_AGENT value. For example, running CF on my localhost produces HTTP_USER_AGENT=Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070515 Firefox/

          By testing this CGI variable, you will be able to determine where your users are coming from.
          • 2. Re: Page Redirects For Mobile Devices
            Bearded Coffee Monkey Level 1
            Ahh, ok. I have that.
            I don't suppose there is a comperhensive list of either desktop browsers and/or mobile device browsers to do my cross checking with?

            Just a simple "if CGI.HTTP_USER_AGENT contains foo then bar" type setup.
            • 3. Re: Page Redirects For Mobile Devices
              tclaremont Level 2
              How about using javascript to detect the screen resolution, and redirecting the user to the appropriate page if it is below 640 x 480 or so???

              Here is a sample script that I came across that you should be able to modify to suit your needs:

              <SCRIPT LANGUAGE="JavaScript">
              <!-- Begin
              function redirectPage() {
              var url640x480 = " http://www.yoursite.com/640x480";
              var url800x600 = " http://www.yoursite.com/800x600";
              var url1024x768 = " http://www.yoursite.com/1024x768";
              if ((screen.width == 640) (screen.height == 480))
              window.location.href= url640x480;
              else if ((screen.width == 800) (screen.height == 600))
              window.location.href= url800x600;
              else if ((screen.width == 1024) (screen.height == 768))
              window.location.href= url1024x768;
              else window.location.href= url640x480;
              // End -->
              • 4. Re: Page Redirects For Mobile Devices
                I've just spent a couple of days trying different ideas for using the WURFL XML
                document with CF, for detecting mobile devices. WURFL (Wireless Universal Resource
                File) is a project organized by Luca Passani, which collects information on mobile
                devices and organizes the info in an XML document format. More info on WURFL is at

                The first thing is to download the WURFL document file from the website given above.
                I setup a scheduled weekly download.

                The WURFL document is about 7mb so you want to get it into an application variable for quicker access.
                Insert the first block of attached code into your application.cfm file. Modify the file path to where you downloaded the WURFL file.

                Now insert the second block of code into a file that you will cfinclude in any page you want
                redirected to the mobile website. Modify the web site address.

                When a desktop browser is detected, the array (wurfl2) will be empty, so no redirect occurs.
                If a mobile browser is detected, the array will contain all of the pertinent infomation that the WURFL document has regading the detected browser, if you want to use it to customize your output.
                • 5. Re: Page Redirects For Mobile Devices
                  We at dotMobi have a device detection system called DeviceAtlas which has a downloadable API written in Java that I think would solve your problem.

                  Unfortunately there are new devices and browsers in the market every day so trying to keep track is hard work. DeviceAtlas has a downloadable datafile which is updated daily with all the latest data we cgather from numerous sources including WURFL, mobile operators and manufacturers.

                  I would be very interested to hear how you get on testing DA in a ColdFusion environment. You can download the API and get a free Developer licence for the data file from DeviceAtlas.com.

                  Why not give it a shot in CF and let me know what you think I'd be very keen to help you get it running.

                  Version 2 of our API is due for release Feb 2nd, but I could send you a pre-release test version to try out if you like.

                  I've attached some code showing how I think you could use our API (Version 2) in CF.

                  Adrian Hope-Bailie