Browser version detect using GWT?

Stevko picture Stevko · Jun 17, 2010 · Viewed 20.8k times · Source

Is there GWT api that will tell me which browser version it detected?

I've found a flaw with IE7's regex handling and need to code around some tricky String.matches() expressions.

Answer

Romain Hippeau picture Romain Hippeau · Jun 17, 2010

You can detect the browser type using the code below.

public static native String getUserAgent() /*-{
return navigator.userAgent.toLowerCase();
}-*/;

Then you can call that function and look at the type of the browser. For example the code below decides whether it is internet explorer or not.

if(getUserAgent().contains("msie"))
{
///////// Write your code for ie
}

This page has the User Agent for just about every browser known to man.