On my gwt project. i have a script that call the dictionary:
<script type="text/javascript" src=conf/iw_dictionary.js></script>
instead of writing this script element in the html file. i want to inject it into the html from the entry point, on the module load.
how can i do it?
You could simply add a
<script>
element in your *.gwt.xml file.onModuleLoad
will only be called once the script is loaded (as if you had it in your html page).Use
com.google.gwt.core.client.ScriptInjector
, since it was created specifically for stuff like thisThe answers form jusio, Dom and Thomas Broyer are all valid here. In my particular case, I was looking to inject a series of polyfill scripts into GWT for some IE8 support we needed when running native JS code. The polyfill scripts needed to be available to the GWT iframe's window context - NOT the host page. To do that, using
ScriptInjector
was the correct approach as it attaches the script at that level. You can makeScriptInjector
install the scripts to a host window by usingsetWindow(TOP_WINDOW)
. Adding scripts with the<script>
tag in my *.gwt.xml file seemed to be attaching to the host window as did using @Dom's approach.Basically you inject the script element in your onModuleLoad():
The browser will automatically load it as soon as it's injected.