Solved

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

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

Accepted Solution

by:
rlavalle earned 20 total points
Comment Utility
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

Superior storage. Superior surveillance.

WD Purple drives are built for 24/7, always-on, high-definition security systems. With support for up to 8 hard drives and 32 cameras, WD Purple drives are optimized for surveillance.

Join & Write a Comment

Suggested Solutions

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now