Re: Browser Version Detection
Re: Browser Version Detection
- Subject: Re: Browser Version Detection
- From: David Teran <email@hidden>
- Date: Wed, 3 Sep 2003 12:12:00 +0200
Hi,
this code should be available in project wonder now ;-)
cheers, David
On 03.09.2003, at 11:58, Jonathan Fleming wrote:
I've found some archived code that I've only slightly updated but it
seems that when I'm using Netscape 3.0, 4.79 or 6.2 the browser
version always reads out as version 5.0 or 5.5...
Can anyone tell me if I have something wrong in this class.
The validation of Internet Explorer seems to be fine however.
Here's the code:
import com.webobjects.foundation.*;
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;
import com.webobjects.eoaccess.*;
public class BrowserDetector extends WOSession {
protected boolean isIE;
protected boolean isNetscape;
protected boolean isICab;
protected boolean isMac;
protected boolean isWindows;
protected boolean isLinux;
protected boolean isVersion3;
protected boolean isVersion4;
protected boolean isVersion5;
protected boolean isVersion6;
protected boolean isVersion7;
protected String plattform;
protected String version;
protected String browser;
protected boolean browserVerOveride;
/*
* constructor
*/
public BrowserDetector() {
super();
}
/*--------------------------------------------------*/
public void awake() {
super.awake();
WORequest r = context().request();
String userAgent = r.headerForKey("User-Agent");
if (userAgent.indexOf("Mozilla")!=-1) {
isNetscape=true;
isICab=isIE=false;
browser="Netscape";
}
if (userAgent.indexOf("iCab")!=-1) {
isICab=true;
isIE=isNetscape=false;
browser="iCab";
}
if (userAgent.indexOf("MSIE")!=-1) {
isIE=true;
isICab=isNetscape=false;
browser="MSIE";
}
if (userAgent.indexOf("Win")!=-1) {
isMac=isLinux=false;
isWindows=true;
plattform="Windows";
} else if (userAgent.indexOf("Mac")!=-1) {
isWindows=isLinux=false;
isMac=true;
plattform="Mac";
} else if (userAgent.indexOf("Linux")!=-1) {
isWindows=isMac=false;
isLinux=true;
plattform="Linux";
}
if (userAgent.indexOf("7.0")!=-1 ||
userAgent.indexOf("7.1")!=-1) {
isVersion6=isVersion5=isVersion4=isVersion3=false;
isVersion7=true;
version="7.0 or 7.1";
} else if (userAgent.indexOf("6.0")!=-1) {
isVersion5=isVersion4=isVersion3=isVersion7=false;
isVersion5=true;
version="6.0";
} else if (userAgent.indexOf("5.0")!=-1 ||
userAgent.indexOf("5.5")!=-1) {
isVersion4=isVersion3=isVersion6=isVersion7=false;
isVersion5=true;
version="5.0 or 5.5";
} else if (userAgent.indexOf("4.0")!=-1 ||
userAgent.indexOf("4.5")!=-1 ||
userAgent.indexOf("4.7")!=-1) {
isVersion3=isVersion5=isVersion6=isVersion7=false;
isVersion4=true;
version="4.0, 4.6, 4.7";
} else if (userAgent.indexOf("3.0")!=-1) {
isVersion4=isVersion5=isVersion6=isVersion7=false;
isVersion3=true;
version="3.0";
}
System.out.println("\r=================================================
=====\r Browser="+browser+" Plattform="+plattform+"
Version="+version+"...\r");
}
/*-------------------------------------------*/
public String getVersion() {
return version;
}
public void setVersion(String value) {
version = value;
}
/*-------------------------------------------*/
public String getBrowser() {
return browser;
}
public void setBrowser(String value) {
browser = value;
}
/*-------------------------------------------*/
public boolean getBrowserVerOveride() {
return browserVerOveride;
}
public void setBrowserVerOveride(boolean value) {
browserVerOveride = value;
}
/*-------------------------------------------*/
public boolean isValidBrowser() {
if (browserVerOveride==false){
return false;
}
else if ((getBrowser().equals("Netscape")) &&
(getVersion().equals("7.0")) ||
(getBrowser().equals("MSIE")) &&
(getVersion().equals("6.0") ||
getVersion().equals("7.0")))
{
return true;
}
else
{
return false;
}
}
}
Kind regards
Jonathan :^)
_________________________________________________________________
Sign-up for a FREE BT Broadband connection today!
http://www.msn.co.uk/specials/btbroadband
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.