如何了解 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
跨浏览器支持上的 GWT 开发人员指南页面提供了一个 JSNI 函数,该函数返回 UserAgent 字符串。
但请注意,您可能希望使用延迟绑定来编写浏览器- 特定代码,而不是检测 UserAgent。
编辑:Kasturi 指出Window.Navigator.getUserAgent(),其实现方式如下:
所以是的,这应该执行跨浏览器支持页面上提到的函数的作用(只不过它不会调用 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:
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.