Is there GWT api that will tell me which browser version it detected?
I've found a flaw with IE7's regex handling and need to code around some tricky String.matches() expressions.
Is there GWT api that will tell me which browser version it detected?
I've found a flaw with IE7's regex handling and need to code around some tricky String.matches() expressions.
You could use GWT deferred binding using replacement and create two implementations of your class in which you use regex.
For example let's assume your class is named Parser
and it contains code for all web browsers except for IE7. Then you can extend Parser
and create ParserIE7
class for IE7. Then in your GWT module config file you can add:
<replace-with class="Parser">
<when-type-is class="Parser"/>
</replace-with>
<replace-with class="ParserIE7">
<when-type-is class="Parser" />
<when-property-is name="user.agent" value="ie7"/>
</replace-with>
Then by calling
Parser parser = GWT.create(Parser.class);
you should have a proper (web browser dependent) implementation of Parser
in parser
variable.
You can find more details here.
You can detect the browser type using the code below.
public static native String getUserAgent() /*-{
return navigator.userAgent.toLowerCase();
}-*/;
Then you can call that function and look at the type of the browser. For example the code below decides whether it is internet explorer or not.
if(getUserAgent().contains("msie"))
{
///////// Write your code for ie
}
This page has the User Agent for just about every browser known to man.
Window.Navigator.getUserAgent()
instead of your JSNI method? –
Midway msie
. One should use contains("msie") || contains("trident")
to match IE11. –
Splay You could use GWT deferred binding using replacement and create two implementations of your class in which you use regex.
For example let's assume your class is named Parser
and it contains code for all web browsers except for IE7. Then you can extend Parser
and create ParserIE7
class for IE7. Then in your GWT module config file you can add:
<replace-with class="Parser">
<when-type-is class="Parser"/>
</replace-with>
<replace-with class="ParserIE7">
<when-type-is class="Parser" />
<when-property-is name="user.agent" value="ie7"/>
</replace-with>
Then by calling
Parser parser = GWT.create(Parser.class);
you should have a proper (web browser dependent) implementation of Parser
in parser
variable.
You can find more details here.
If you are using the GXT library, you can use GXT.isChrome to detect chrome and you can find different data members of GXT class to detect a particular browser.
© 2022 - 2024 — McMap. All rights reserved.