I work with GWT. I looked at the methods of Window.Navigator , but none of them returns the user's browser. I need to know if the user is using Safari. How to do it in GWT?
3 answers
Try using Deferred Binding . This will almost certainly allow you to do what you need.
And what does Window.Navigator.getUserAgent () not suit you? After all, it will be seen which browser is being referred to ...
- There are a lot of things written there, and not just the name of the browser + version. :( - angry
- Parsite Comrade) - Sergey
- So there are several browsers indicated at once! - angry
- the value of this parameter has deep historical roots, but there is still a certain format, see at least en.wikipedia.org/wiki/User_agent . - yozh
- oneAnd yet I advise Deferred Binding. He solves similar problems at times. - cy6erGn0m
|
At one time, this problem was solved as follows:
public static BrowserType getBrowserType() { String browserName = getBrowserTypeString(); BrowserType result; if (browserName.indexOf("msie 7.0") != -1) { result = BrowserType.INTERNET_EXPLORER_7; } else if (browserName.indexOf("msie 6.0") != -1) { result = BrowserType.INTERNET_EXPLORER_6; } else if (browserName.indexOf("msie") != -1) { result = BrowserType.INTERNET_EXPLORER_OTHER; }else if (browserName.indexOf("gecko") != -1) { result = BrowserType.MOZILLA_FIREFOX; } else if (browserName.indexOf("opera") != -1) { result = BrowserType.OPERA; } else if (browserName.indexOf("webkit") != -1) { result = BrowserType.SAFARI; } else { result = BrowserType.UNDEFINED; } return result; } private static native String getBrowserTypeString() /*-{ return navigator.userAgent.toLowerCase(); }-*/; public static enum BrowserType{ MOZILLA_FIREFOX, INTERNET_EXPLORER_6, INTERNET_EXPLORER_7, INTERNET_EXPLORER_OTHER, OPERA, SAFARI, UNDEFINED }
- 21. Your code will show that Chrome is Safari, 2. Why is the native code here, if there is Window.Navigator.getUserAgent (). ToLowerCase ()! - Nicolas Chabanovsky ♦
|
See how this is done in com.google.gwt.dev.util.BrowserInfo
- > Why is the native code here, if there is Window.Navigator.getUserAgent (). ToLowerCase () Well, no harm - the semantics is the same. > com.google.gwt.dev.util.BrowserInfo The fact that there is a standard implementation is good. In our project, this code has been used for quite some time (as far as I remember, GWT 2.0 has not yet appeared and Chrome has just appeared) and we needed to distinguish between versions of Internet Explorer. > Chrome is Safari. That's right - they have [the engine] [1] one [1]: en.wikipedia.org/wiki/WebKit - Ivan Golubev
|