GWT将脚本元素注入到html文件中 [英] GWT inject script element into the html file

查看:87
本文介绍了GWT将脚本元素注入到html文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的gwt项目上。我有一个脚本调用字典:

 < script type =text / javascriptsrc = conf / iw_dictionary.js> ;< /脚本> 

而不是在html文件中写入此脚本元素。我希望将它从入口点注入到模块加载中。



我该怎么做?

解决方案使用 com.google.gwt.core.client.ScriptInjector ,因为它是专门为这样的东西创建的

  ScriptInjector.fromUrl(conf / iw_dictionary.js)。setCallback(
new回调< Void,Exception>(){
public void onFailure(Exception reason){
Window.alert(Script load failed。);
}
public void onSuccess无效结果){
Window.alert(Script load success。);
}
})。inject();


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?

解决方案

Use com.google.gwt.core.client.ScriptInjector, since it was created specifically for stuff like this

ScriptInjector.fromUrl("conf/iw_dictionary.js").setCallback(
  new Callback<Void, Exception>() {
     public void onFailure(Exception reason) {
       Window.alert("Script load failed.");
     }
    public void onSuccess(Void result) {
      Window.alert("Script load success.");
     }
  }).inject();

这篇关于GWT将脚本元素注入到html文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆