1

I've got a JavaScript fix specifically for IE9 and want to load it into my project only for that browser. I thought I might be able to do something like this in my .gwt.xml:

<script src="ie9svgfix.js">
    <when-property-is name="user.agent" value="ie9"/>
</script>

But unfortunately this doesn't work. Does anybody know a clean way to do this in GWT?

Thanks,

Jon

2 Answers 2

3

You can try conditional comments:

<!--[if IE 9]>
<script src="ie9svgfix.js"></script>
<![endif]-->
Sign up to request clarification or add additional context in comments.

Comments

3

The cleanest way in GWT would be to use deferred-binding and inject the script with the ScriptInjector in the IE9 permutation; or have the script loaded by the host page, in which case you can use conditional comments (as suggested by Stano).

With deferred-binding, you'd have to create a class to "deferred-bind" with a specific implementation for IE9.

class SvgFix {
  public void fix() { /* no op */ }
}

class SvgFixIE9 {
  @Override
  public void fix() {
    ScriptInjector.fromUrl(GWT.getModuleBaseForStaticFiles() + "ie9svgfix.js")
        .setWindow(ScriptInjector.TOP_WINDOW)
        .inject();
  }
}

And in your EntryPoint, inject the script:

GWT.<SvgFix>create(SvgFix.class).fix();

And finally then choose the appropriate implementation based on permutation:

<replace-with class="com.example.client.SvgFixIE9">
  <when-type-assignable class="com.example.client.SvgFix" />
  <when-property-is name="user.agent" value="ie9" />
</replace-with>

BTW, note that <script> in gwt.xml files is not supported with the xsiframe linker, and I'd encourage you to use it going forward (it has all the advantages of all the other linkers, and none of their drawbacks, plus it adds Super Dev Mode, flexibility/configurability, etc.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.