• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 320
  • Last Modified:

How to show browser name and version

Hi, all

I tried to use:

System.out.println("browser: " + System.getProperty("browser"));
System.out.println("browser version: " + System.getProperty("browser.version"));

to show browser name and version information. But it shows null. Could you please help me fix it? Thanks.
0
CodeLover
Asked:
CodeLover
1 Solution
 
bobbit31Commented:
see here:

http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=7&t=000288

specifically:

private String getBrowserType(String currValue){
String browser = new String("");
String version = new String("");
if(currValue != null ){
if((currValue.indexOf("MSIE") == -1) && (currValue.indexOf("msie") == -1)){
browser = "NS";
int verPos = currValue.indexOf("/");
if(verPos != -1)
version = currValue.substring(verPos+1,verPos + 5);
}
else{
browser = "IE";
String tempStr = currValue.substring(currValue.indexOf("MSIE"),currValue.length());
version = tempStr.substring(4,tempStr.indexOf(";"));

}

}
System.out.println(" now browser type is " + browser +" " + version);

return browser + " " + version;

}

which you would call by doing:

String browser = getBrowserType(request.getHeader("USER-AGENT"));
0
 
cheekycjCommented:
bobbit31 is right.  What you are using is for locally set properties not for user's browsers.

The code provided should work.

CJ
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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now