com.maryanovsky.gwtutils.client
Class BrowserUtils

java.lang.Object
  extended by com.maryanovsky.gwtutils.client.BrowserUtils

public class BrowserUtils
extends Object

Various browser related or browser specific utilities.

Author:
Maryanovsky Alexander

Field Summary
static String USER_AGENT
          The user-agent string of the browser we are running in.
 
Constructor Summary
BrowserUtils()
           
 
Method Summary
static int compareVersions(String version1, String version2)
          Compares two version numbers of something.
static String getAppleWebKitVersion()
          Returns the AppleWebKit version number.
static double getDevicePixelRatio()
          Returns the value of window.devicePixelRatio, or 1 if there's no such property.
static String getGeckoVersion()
          Returns the Gecko version number.
static String getHostname()
          Returns the hostname of the URL at which this application is running.
static String getHostPageUrl()
          Returns the full URL of the host webpage.
static String getIEVersion()
          Returns the version of IE we're running in.
static String getPathname()
          Returns the pathname of the URL at which this application is running.
static String getSafariVersion()
          Returns the Safari version number (the one used for marketing, like 4.0).
static boolean hasTouchEventsSupport()
          Returns whether the browser supports touch events.
static boolean isAndroid()
          Returns whether we are running on an Android device.
static boolean isAppleWebKit()
          Returns whether we are running in an AppleWebKit browser.
static boolean isAppleWebKitOnAndroid()
          Returns whether we are running in an AppleWebKit browser, on an Android device.
static boolean isGecko()
          Returns whether we are running in a Gecko based browser.
static boolean isIE()
          Returns whether we are running in MSIE.
static boolean isIE6()
          Returns whether we are running in MSIE 6.
static boolean isIE7()
          Returns whether we are running in MSIE 7.
static boolean isIE8()
          Returns whether we are running in MSIE 8.
static boolean isLinux()
          Returns whether we're running on Linux.
static boolean isMacOS()
          Returns whether we're running on Mac OS.
static boolean isMobileAppleWebKit()
          Returns whether we are running in a mobile version of an AppleWebKit browser.
static boolean isMozilla()
          Returns whether we are running in a Mozilla browser.
static boolean isOpera()
          Returns whether we are running in Opera.
static boolean isSafari()
          Returns whether we are running in Safari.
static boolean isWindows()
          Returns whether we're running on MS Windows.
static void setDocumentLocation(String location)
          Sets document.location to the specified value.
static void setStatus(String statusText)
          Sets the status of the window we're running in to the specified string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USER_AGENT

public static final String USER_AGENT
The user-agent string of the browser we are running in.

Constructor Detail

BrowserUtils

public BrowserUtils()
Method Detail

isIE

public static boolean isIE()
Returns whether we are running in MSIE.


isIE6

public static boolean isIE6()
Returns whether we are running in MSIE 6.


isIE7

public static boolean isIE7()
Returns whether we are running in MSIE 7.


isIE8

public static boolean isIE8()
Returns whether we are running in MSIE 8.


getIEVersion

public static String getIEVersion()
Returns the version of IE we're running in.


isOpera

public static boolean isOpera()
Returns whether we are running in Opera.


isSafari

public static boolean isSafari()
Returns whether we are running in Safari.


getSafariVersion

public static String getSafariVersion()
Returns the Safari version number (the one used for marketing, like 4.0). Returns an empty string if unable to detect.


isAppleWebKit

public static boolean isAppleWebKit()
Returns whether we are running in an AppleWebKit browser.


isMobileAppleWebKit

public static boolean isMobileAppleWebKit()
Returns whether we are running in a mobile version of an AppleWebKit browser.


getAppleWebKitVersion

public static String getAppleWebKitVersion()
Returns the AppleWebKit version number. Returns an empty string if unable to detect (possibly because we're not running in an AppleWebKit browser).


isAndroid

public static boolean isAndroid()
Returns whether we are running on an Android device.


isAppleWebKitOnAndroid

public static boolean isAppleWebKitOnAndroid()
Returns whether we are running in an AppleWebKit browser, on an Android device.


isMozilla

public static boolean isMozilla()
Returns whether we are running in a Mozilla browser.


isGecko

public static boolean isGecko()
Returns whether we are running in a Gecko based browser.


getGeckoVersion

public static String getGeckoVersion()
Returns the Gecko version number. Returns an empty string if unable to detect (possibly because we're not running in a Gecko browser).


isWindows

public static boolean isWindows()
Returns whether we're running on MS Windows.


isMacOS

public static boolean isMacOS()
Returns whether we're running on Mac OS.


isLinux

public static boolean isLinux()
Returns whether we're running on Linux.


compareVersions

public static int compareVersions(String version1,
                                  String version2)
Compares two version numbers of something. Returns a negative value if the first number is less than the 2nd, zero if they are equal, and a positive value if the first version number is larger than the second version number. The separator between major, minor and other sub-version numbers is assumed to be a period.


getHostPageUrl

public static String getHostPageUrl()
Returns the full URL of the host webpage.


getHostname

public static String getHostname()
Returns the hostname of the URL at which this application is running.


getPathname

public static String getPathname()
Returns the pathname of the URL at which this application is running.


setDocumentLocation

public static void setDocumentLocation(String location)
Sets document.location to the specified value.


setStatus

public static void setStatus(String statusText)
Sets the status of the window we're running in to the specified string.


getDevicePixelRatio

public static double getDevicePixelRatio()
Returns the value of window.devicePixelRatio, or 1 if there's no such property.


hasTouchEventsSupport

public static boolean hasTouchEventsSupport()
Returns whether the browser supports touch events. Note that his doesn't necessarily mean that we're running on a touch device, as some desktop browsers may report touch events support.