get Browser Type from user agent - Java Network

Java examples for Network:User Agent

Description

get Browser Type from user agent

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String UserAgent = "java2s.com";
        System.out.println(getBrowserType(UserAgent));
    }//  w ww. jav  a 2 s .c  om

    public static String getBrowserType(String UserAgent) {
        if (UserAgent.toLowerCase().indexOf("firefox") != -1) {
            return "firefox";
        } else if (UserAgent.toLowerCase().indexOf("msie") != -1) {
            return "IE";
        } else {
            return "other";
        }

    }
}

Related Tutorials