如何了解 GWT 中的用户代理

发布于 2024-08-31 11:21:01 字数 49 浏览 5 评论 0原文

我正在尝试编写浏览器特定的代码。是否有 GWT API 可以找出客户端使用的浏览器?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流星番茄 2024-09-07 11:21:01

跨浏览器支持上的 GWT 开发人员指南页面提供了一个 JSNI 函数,该函数返回 UserAgent 字符串。

但请注意,您可能希望使用延迟绑定来编写浏览器- 特定代码,而不是检测 UserAgent。

编辑:Kasturi 指出Window.Navigator.getUserAgent(),其实现方式如下:

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

所以是的,这应该执行跨浏览器支持页面上提到的函数的作用(只不过它不会调用 toLowerCase() ),不过您最好还是使用延迟绑定。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文