I'm trying to change the user agent to safari when the page is visited using IE9.
I wrote this to the gwt.xml file:
<set-property name='user.agent' value='safari'>
<when-property-is name="user.agent" value="ie9" />
</set-property>
However IE9 now doesn't find any user agent at all (doesn't even fall back to its own). What am I doing wrong?
EDIT: I have to use GWT 2.0.4
EDIT2: Read comments of answer to see how I fixed it.
I haven't done it before, but I assume you will have to implement your own UserAgentPropertyGenerator (because this is the class that evaluates the user agent property dynamically!), and then bind it like in com.google.gwt.user.UserAgent.gwt.xml:
<property-provider
name="user.agent"
generator="com.google.gwt.user.rebind.UserAgentPropertyGenerator"/>
For older versions of GWT (< 2.3.0), this is configured directly in com.google.gwt.user.UserAgent.gwt.xml as:
<property-provider name="user.agent"><![CDATA[
var ua = navigator.userAgent.toLowerCase();
var makeVersion = function(result) {
return (parseInt(result[1]) * 1000) + parseInt(result[2]);
};
if (ua.indexOf("opera") != -1) {
return "opera";
} else if (ua.indexOf("webkit") != -1) {
return "safari";
} else if (ua.indexOf("msie") != -1) {
if (document.documentMode >= 8) {
return "ie8";
} else {
var result = /msie ([0-9]+)\.([0-9]+)/.exec(ua);
if (result && result.length == 3) {
var v = makeVersion(result);
if (v >= 6000) {
return "ie6";
}
}
}
} else if (ua.indexOf("gecko") != -1) {
var result = /rv:([0-9]+)\.([0-9]+)/.exec(ua);
if (result && result.length == 3) {
if (makeVersion(result) >= 1008)
return "gecko1_8";
}
return "gecko";
}
return "unknown";
]]></property-provider>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With