Solved

Browser Detection / Redirection : (pointer to original Q - 125 pts)

Posted on 2004-08-11
1
250 Views
Last Modified: 2013-12-24
0
Comment
Question by:stu215
1 Comment
 
LVL 2

Accepted Solution

by:
rlavalle earned 20 total points
ID: 11785615
Here you go...

Here'a solution using ColdFusion and a tiny bit of JavaScript. ColdFusion has a CGI variable called HTTP_USER_AGENT that holds the browser name and version near the end. I parse this string and check for each of the 3 browser types and their version. You can easily open a ColdFusion page in any browser you want to compare against and determine where in the HTTP_USER_AGENT string the browser name and version is (in case you need to change this in the future).

Oh, and I used the latest version of Safari that I think has been released (125.9) rather than 128.5.

Good luck,
Russ

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<cfscript>

function IsBrowserValid()
{
     browserLoc = 0;
     versNum = 0;
     safari = "Safari";
     msie = "MSIE";
     netscape = "Netscape";
     goodBrowser = false;
     
     browserLoc = FindNoCase(safari, CGI.HTTP_USER_AGENT);
     if (browserLoc)
     {
          versNum = Val(RemoveChars(CGI.HTTP_USER_AGENT, 1, browserLoc + LEN(safari)));
          if (versNum GTE 125.9)
               goodBrowser = true;
     }
     else
     {
          browserLoc = FindNoCase(msie, CGI.HTTP_USER_AGENT);
          if (browserLoc)
          {
               versNum = Val(RemoveChars(CGI.HTTP_USER_AGENT, 1, browserLoc + LEN(msie)));
               if (versNum GTE 6)
                    goodBrowser = true;
          }
          else
          {
               browserLoc = FindNoCase(netscape, CGI.HTTP_USER_AGENT);
               if (browserLoc)
               {
                    versNum = Val(RemoveChars(CGI.HTTP_USER_AGENT, 1, browserLoc + LEN(netscape)));
                    if (versNum GTE 7)
                         goodBrowser = true;
               }
          }
     }
     
     return goodBrowser;
}
</cfscript>

<script language="javascript1.2">
<cfif IsBrowserValid()>
          alert('Browser is valid. You may continue.');
<cfelse>
          alert('Browser is INVALID. You must go away.');
          window.location = "http://www.google.com";
</cfif>
</script>

</body>
</html>
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question