Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out about the User Agent in GWT

Tags:

I am trying to write browser specific code. Is there a GWT API to find out which browser the client is using?

like image 405
Kasturi Avatar asked May 03 '10 15:05

Kasturi


People also ask

How do I access user agent?

Click Develop > User Agent and select the user agent you want to use in the list. If the user agent you want to use isn't shown here, select “Other” and you can provide a custom user agent. You can find extensive lists of user agents on various websites, such as this one.

What does a user agent reveal?

User Agents tell a website what browser you are using Included in that request is the user agent (In a HTTP Header). Web sites can look at that user agent string and determine what web browser, operating system, and device you are using. It's how we tell you "my browser" on our homepage!

What is user agent in logs?

The user agent is an HTTP header that web browsers and other web applications use to identify themselves and their capabilities. Your web security software captures and logs user agent data when users browse the Internet.

What does user agent contain?

A user agent is any software that retrieves and presents Web content for end users or is implemented using Web technologies. User agents include Web browsers, media players, and plug-ins that help in retrieving, rendering and interacting with Web content.


1 Answers

The GWT Developer's Guide page on Cross-Browser Support gives a JSNI function that returns the UserAgent string.

Note, however, that you probably want to use Deferred Binding to write browser-specific code, instead of detecting the UserAgent.

Edit: Kasturi points out Window.Navigator.getUserAgent(), which is implemented like so:

/**
 * Gets the navigator.appName.
 *
 * @return the window's navigator.appName.
 */
public static native String getAppName() /*-{
  return $wnd.navigator.appName;
}-*/;

So yes, this should do what the function mentioned on the Cross-Browser Support page does (except that it doesn't call toLowerCase() on it), though again you may be better off using deferred binding.

like image 112
aem Avatar answered Oct 09 '22 14:10

aem