I am trying to write browser specific code. Is there a GWT API to find out which browser the client is using?
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.
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!
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With