Solved

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

Posted on 2004-08-11
1
255 Views
Last Modified: 2013-12-24
0
Comment
Question by:stu215
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

695 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