如何了解 GWT 中的用户代理 [英] How to find out about the User Agent in GWT

查看:20
本文介绍了如何了解 GWT 中的用户代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

Cross-Browser Support 提供了一个返回 UserAgent 字符串的 JSNI 函数.

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

但是请注意,您可能想要使用延迟绑定编写特定于浏览器的代码,而不是检测 UserAgent.

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

Kasturi 指出 Window.Navigator.getUserAgent(),实现如下:

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;
}-*/;

所以,是的,这应该做跨浏览器支持页面上提到的函数所做的事情(除了它没有调用 toLowerCase() ),尽管再次使用延迟绑定可能会更好.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆