String userAgent = request.getHeader("User-Agent");
String browser = "unknown";
if (userAgent != null) {
userAgent = userAgent.toLowercase();
if (this.userAgent.indexOf("msie") > -1) {
browser = "IE";
} else if (this.userAgent.indexOf("opera") > -1) {
browser = "Opera";
} else if (this.userAgent.indexOf("firefox") > -1) {
browser = "Firefox";
} else if (this.userAgent.indexOf("chrome") > -1) {
browser = "Chrome";
} else if (this.userAgent.indexOf("navigator") > -1) {
browser = "Netscape";
} else if (this.userAgent.indexOf("konqueror") > -1) {
browser = "Konqueror";
}
}
This snippet can be improved upon alot. Hope this is of help to someone.
nice
ReplyDeleteNice blog
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteSept 25, 2008 long time back!, nice snippet.
ReplyDeleteGot an answer to an old question ! Conceptual piece of code.
ReplyDelete