Ask a Jedi: ColdFusion 8 Ajax Features and JavaScript Detection

This post is more than 2 years old.

Justin asks:

CF8 brought us some pretty rad RAD tools for quick and dirty AJAX and SPRY stuff. However, they did not provide a quick and dirty browser detection method to go along with it. I'm using ugly stuff that isn't so rad or RAD to handle this.

Is there something out there we can include in any necessary page that would direct users to an informational page regarding their unsupported browser? The last customer actually had IE7, but their shop has always used Netscape 7. Unfortunately, CFDIV did not like it, but the user had no idea that entire section of information was invisible.

If I were going to program this, what would be the best CF8 way to go about it? A CFC stored in the application scope? Perhaps checkUserAgent() function with a couple of options for the browser requirements? The same CFC could probably have robot checking as well. Naturally, it shouldn't be used for security, but something is definitely needed.

Once someone does this, it should definitely be dropped on RIAForge as I consider all the new CF 8 SPRY tags to be completely useless for Internet sites without browser detection, intranet is just fine.

So first off - I'm not aware of any ColdFusion-based browser detector. I'm sure some exist. I know I wrote code in that area around 7-8 years ago. It can be done - but it tends to be kind of a pain in the rear. I've also used BrowserHawk in the past. This is a third party tool that provides checks for just about everything.

Secondly - browser detection isn't trivial. I don't think its fair at all to call all the cool new Ajax stuff useless. (Note that CF8's Spry integration is just one small part.) Not every organization needs serious browser detection. I rarely see it myself anymore. I do often see "You need X and Y", which I think is fair and - lets face it - a heck of a lot easier then multiple browser detector tests. That's almost like saying ColdFusion's charting features are useless because some people don't have Flash (all 3 of them - they live next door).

You could try a few simple tricks - for example, this code will show a message to folks with JavaScript turned off:

<cfdiv bind="url:test3.cfm"> No JavaScript? You Suck! </cfdiv>

If they have JavaScript turned on, the contents of test3.cfm load. It's a rather trivial trick, but it at least can check for JavaScript access. Once past that your best best is to feature detection, not browser detection. So for example:


Checking for document.images is much simpler than checking a user agent and version, and it accomplishes what you want ("Does the browser support using JavaScript to load images?")

As always - I'm curious as to what others out there are using. Is it just me or are 'browser detector pages' going away?

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Dan Vega posted on 3/14/2008 at 2:59 AM

I am not sure about ColdFusion specific methods. If your page is using any of the Ajax components and Ext is available there are some methods available to you. I threw a quick list together and threw a test into FireBug.


Comment 2 by Tom Mollerus posted on 3/14/2008 at 5:19 AM

I agree with the technique of object detection, which I use all the time. I wonder if you could check for some of the objects unique to CF8, such as the ColdFusion object:
... do something

Unfortunately I don't have a copy of Netscape 7 with which to test.

Comment 3 by David McGuigan posted on 3/14/2008 at 12:16 PM

What's Netscape? Jk.

I was actually looking for a good browser detection solution myself about a week ago and came across this:

It's pretty old, but detected the crap out of the browsers I tried it on and even populates quick and dirty variables like isFirefox, isExplorer, and so on FYC.

I basically just used it to detect for Safari and display the message, "It's nothing personal, but we're going to have to ask that you install a legitimate Web browser to view our site."

And it's worked like a charm.

Comment 4 by David McGuigan posted on 3/14/2008 at 12:18 PM
Comment 5 by Sam Farmer posted on 3/14/2008 at 5:23 PM

You should talk to your three neighbors and sort them out ;)

Comment 6 by Justin posted on 3/14/2008 at 6:30 PM

I only need this for parts of the site that I need to do RAD work with a little flare. Like, get this done in 12 hours sort of thing.

We get about 4.5 million unique visitors per year and about 5% have browsers that ignore SPRY. This is due to very "mature" users and impoverished international users on 2nd hand U.S. PCs.

I really only need to detect older browsers, I'm not worried about feature X or Y. There are good documented cut off points in both SPRY and EXT.

Comment 7 by Justin posted on 3/14/2008 at 6:31 PM

Hey Ray,

Can you remove my email from my name above? Thanks!

Comment 8 by Raymond Camden posted on 3/14/2008 at 6:37 PM


Comment 9 by Drdom posted on 3/14/2008 at 10:26 PM

Agree with Justin - yep, Ajax capabilities in CF8 make it great to develop with, but if you can't be sure of the client you can't use them, end of. You have to revert to something else to be belt and braces.

CF could do with some sort of tools to detect the client environment and manage capababilities as standard. If you have a CFForm type="flash", it would be great if CF could downgrade to a HTML form if there was no Flash.

Maybe this would help against the arguments by the less enlightened that CF's a niche tool for intranets, which I hear a lot.

I have used BrowserHawk a lot and although it's very good, it's also very expensive - if we had built-in browser client environment it would be another feather in the cap.


If it's *REALLY* old browsers you're after you might want to try this as a start

No idea if it works in CF8 out of the box, I used to use it in CF5 quite a bit



Comment 10 by mgwalk posted on 3/28/2008 at 7:15 PM

I think the aebrowser looks good anyone else use it?