如何了解GWT中的用户代理 [英] How to find out about the User Agent in GWT
问题描述
GWT开发人员指南页面跨浏览器支持提供了一个返回UserAgent字符串的JSNI函数。
请注意,您可能想要使用延迟绑定来编写浏览器特定的代码,而不是检测UserAgent。
编辑:Kasturi指出窗口。 Navigator.getUserAgent(),它是这样实现的:
/ **
*获取navigator.appName。
*
* @返回窗口的navigator.appName。
* /
public static native String getAppName()/ * - {
return $ wnd.navigator.appName;
} - * /;
所以是的,这应该是在跨浏览器支持页面上提到的功能它不会对它调用toLowerCase()),虽然再次使用延迟绑定可能会更好。
I am trying to write browser specific code. Is there a GWT API to find out which browser the client is using?
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.
这篇关于如何了解GWT中的用户代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!