How to find out about the User Agent in GWT

前端 未结 1 1991
花落未央
花落未央 2020-12-15 18:01

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

相关标签:
1条回答
  • 2020-12-15 18:59

    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.

    0 讨论(0)
提交回复
热议问题