Detecting Browsers Using Coldfusion

Here we go.. First of all we will how we can call this Browser Function:

The calling is quite simple...

  <cf_getBrowser />
<cfif browser.is_opera>
<cfinclude template="opera.cfm">
<cfelseif browser.is_mozilla>
<cfinclude template="mozilla.cfm">
<cfelseif browser.is_safari>
<cfinclude template="safari.cfm">
<cfelseif browser.is_ie>
<cfinclude template="ie.cfm">
</cfif>
<cfoutput>
You are using: #browser.name#, version #browser.version#
</cfoutput>
<cfdump var="#browser#" />

The above will display the contents related to the specific Browser. You can use the contents of CSS in these include files. If you are unable how we can include CSS in CFM file, see my Themeing Tutorial that is very to follow.

So after now the meat of the Application. Credit goes to original Author here, i Just edited it a bit that's All.

  <cfparam name = "version" default = "0">
<cfparam name="attributes.useragent" default="">
<cfif attributes.useragent is "">
<cfset userAgent=cgi.HTTP_USER_AGENT>
<cfelse>
<cfset userAgent=attributes.useragent>
</cfif>
<cfset browser=StructNew()>
<!--- Initiating struct --->
<cfset browser.name="Unknown">
<cfset browser.version=0>
<cfset browser.is_ie=false>
<cfset browser.is_opera=false>
<cfset browser.is_webtv=false>
<cfset browser.is_lynx=false>
<cfset browser.is_links=false>
<cfset browser.is_konqueror=false>
<cfset browser.is_gecko=false>
<cfset browser.is_safari=false>
<cfset browser.is_mozilla=false>
<cfset browser.is_netscape=false>

<cfif userAgent neq "">
<cfset browser.is_ie=iif(findnocase("MSIE", userAgent,1) is 0, de("false"), de("true"))>
<cfset browser.is_opera=iif(findnocase("Opera", userAgent,1) is 0, de("false"), de("true"))>
<cfset browser.is_webtv=iif(findnocase("webtv", userAgent,1) is 0, de("false"), de("true"))>
<cfset browser.is_lynx=iif(findnocase("Lynx", userAgent,1) is 0, de("false"), de("true"))>
<cfset browser.is_links=iif(findnocase("Links", userAgent,1) is 0, de("false"), de("true"))>
<cfset browser.is_konqueror=iif(findnocase("Konqueror",userAgent,1) is 0, de("false"), de("true"))>
<cfset browser.is_gecko=iif(findnocase("gecko", userAgent,1) is 0, de("false"), de("true"))>
<cfset browser.is_safari=iif(findnocase("Safari", userAgent,1) is 0, de("false"), de("true"))>
<cfset browser.is_mozilla=false>
<cfset browser.is_netscape=iif(findnocase("Mozilla", userAgent,1) is 0, de("false"), de("true"))>
<!--- Detect Opera Netscape (Mozilla) spoofing, rule out Mozilla compatibles and spoofers --->
<cfif browser.is_opera or browser.is_safari or (findnocase("compatible", userAgent,1) gt 0 or findnocase("spoofer", userAgent,1) gt 0)>
<cfset browser.is_netscape=false>
</cfif>
<!--- Detect Opera IE spoofing --->
<cfif browser.is_ie and browser.is_opera>
<cfset browser.is_ie=false>
</cfif>
<!--- IE --->
<cfif browser.is_ie is TRUE>
<cfset browser.name = "Internet Explorer">
<cfset browser.version = val(mid(userAgent,findnocase("MSIE", userAgent,1)+4,4))>
<!--- Opera --->
<cfelseif browser.is_opera is TRUE>
<cfset browser.name = "Opera">
<cfset browser.version = val(mid(userAgent,findnocase("Opera", userAgent,1)+6,4))>
<!--- Mac OSX Safari --->
<cfelseif browser.is_safari>
<cfset browser.name = "Safari">
<cfset browser.version= val(mid(userAgent,find("Safari/",userAgent) + 7, 2))>
<cfset browser.is_gecko=false>
<!--- Netscape, Mozilla and Mozilla based browsers --->
<cfelseif browser.is_netscape is true>
<cfif browser.is_gecko>
<!--- Nestcape >= 6.X (gecko based) --->
<cfset nav6_pos=findnocase("Netscape", userAgent,1)>
<cfif nav6_pos gt 0>
<cfset startpos=nav6_pos+10>
<cfset browser.version=val(mid(userAgent,startpos,4))>
<cfset browser.name = "Netscape">
<cfset browser.version = version>
<cfelse>
<cfset browser.is_netscape=false>
<cfset browser.is_mozilla=true>
<!--- Mozilla < 1.1 --->
<cfset browser.version=val(mid(userAgent,findnocase(")",userAgent,1)-5,5))>
<!--- Mozilla (> 1.1) --->
<cfif browser.version is 0>
<cfset parantes = structnew()>
<cfset parantes.start = find("(",userAgent)>
<cfset parantes.slutt = find(")",userAgent)>
<cfif (parantes.start gt 0) and (parantes.slutt gt parantes.start)>
<cfset browser.version = val(RemoveChars(listlast(mid(user_agent,parantes.start,parantes.slutt - parantes.start), ";"),1,4))>
</cfif>
</cfif>
<cfif Find("Firebird",userAgent) gt 0 or Find("Phoenix", userAgent) gt 0>
<cfset browser.name = "Mozilla Firebird">
<cfelseif Find("Camino", userAgent) gt 0 or Find("Chimera", userAgent) gt 0>
<cfset browser.name = "Camino">
<cfelse>
<cfset browser.name = "Mozilla">
</cfif>
<cfset browser.geckobuild = val(mid(userAgent,find("Gecko",userAgent) + 6, 8))>
</cfif>
<cfelse>
<!--- Netscape <= 4.x --->
<cfset versjon=Val(mid(userAgent,9,4))>
</cfif>

<cfelseif browser.is_lynx>
<cfset browser.name = "Lynx">
<cfset browser.version=Val(mid(userAgent,FindNoCase("Lynx",userAgent) + 5,6))>

<cfelseif browser.is_links>
<cfset browser.name = "Links">
<cfset browser.version=Val(mid(userAgent,9,4))>

<cfelseif browser.is_konqueror>
<cfset browser.name = "Konqueror">
<cfset browser.version=Val(mid(userAgent,FindNoCase("Konqueror",userAgent)+10,6))>
<!--- Unknown browser --->
<cfelse>
<cfset browser.name = userAgent>
<cfset browser.version = 0>
</cfif>
</cfif>
<cfset caller.browser = browser>
<cfset thistag.generatedcontent = "">

All ColdFusion Tutorials By Author: Gurpreet Singh Randhawa
  • Validating Multiple Email Addresses.
    The Tutorial is reagarding the checking of the multiple email addresses. This is a server side coding using the ReFind and the Replace Functions.
    Author: Gurpreet Singh Randhawa
    Views: 11,992
    Posted Date: Friday, April 6, 2007
  • How to Map Multiple Markers Using Coldfusion & Google Map

    Hi Guys! You have sen many applications with google maps and coldfusion showing a specific markers on the map. Most use Custom Coldfusion based tag to show markers on the website. That is also true. But here i will simply use the javascript and the XML functionality to show multiple markers.

    Evrything is possible with Custom tag, but suppose your host does not allow you to use any custom tag and then u desperately looking a solution something like. Here is the solution for you.

     Very Basic Coldfusion Code is used and i have explained everything in detail for you better understanding

    So we begin now:


    Author: Gurpreet Singh Randhawa
    Views: 3,409
    Posted Date: Monday, August 24, 2009
  • Styling website with various fonts

    This is a Small tutorial where you can style your website with multiple fonts. Just choose the font from the database. very handy and it can make you website look different. It can be tweeked to many phases. think as gar as you can and make the tweek as good as you can. here i have just provided a base how we can play with fonts and many other things. it has not been tested on railo and bluedragon but i think it will work


    Author: Gurpreet Singh Randhawa
    Views: 2,473
    Posted Date: Thursday, September 24, 2009
  • Banning The website With Simple Technique

    A Complete Banning Tutorial where you can add as many ipaddresses as you can and any request coming from that relevan Ipaddress will block the user from accessig the website contents. Very Basic and very easy to follow Up. Mail Me anytime if you encounter certain issues while making the script to work.

    You can add upto unlimited ipaddresses where you can block any unauthorized access to the website.


    Author: Gurpreet Singh Randhawa
    Views: 2,576
    Posted Date: Thursday, October 22, 2009
  • Podcast Using Coldfusion and XML

    A Complete Way how we can add a fetch a Podcast and display on the website. Very easy with just Simple XML Tags. the Tutorial has been Influenced by various Peoples works and Finally i came Up with this. Check and You will have the Podcast view for your own website.


    Author: Gurpreet Singh Randhawa
    Views: 2,767
    Posted Date: Thursday, October 22, 2009
  • captcha Code using Coldfusion 8 advanced technique

     be using the avacedA Small Code where we will be shuffling the code of captcha to display the 6 random number at a time. The Captcha Build is also a Case-Senstive match and made with a bit difficulty to Judge with a small Thinking.


    Author: Gurpreet Singh Randhawa
    Views: 4,497
    Posted Date: Monday, December 28, 2009
  • Detecting Browsers Using Coldfusion
    A Custom Tag in which you will be able to find out what exactly the user is using and then you can change the CSS File according to that specific browser. I Rec-worked this Custom Tag a bit to make it work more better and include some extra browser. Still the Credit goes to Original Browser whose Name i do not Know Really. You will find the code very Handy as it will help in making your website browser-specific and great look to end Users.
    Author: Gurpreet Singh Randhawa
    Views: 3,597
    Posted Date: Thursday, January 28, 2010
Download the EasyCFM.COM Browser Toolbar!