当我以这种方式注入javascript:
ScriptInjector.fromString("var WRInitTime=(new Date()).getTime();").inject();
ScriptInjector.fromString(Resources.instance.clicktaleScript().getText()).inject();
我可以看到注入的脚本是在IFRAME中。注入Javascript代码的GWT方法是什么?考虑到页面是“Ajax”或动态。目标是使Clicktale脚本能够记录浏览器事件,就像它对普通HTML页面的工作方式一样,这使得使用带有Ajax数据的Dynamic网站工作非常困难。
实际的JS脚本是:
<!-- ClickTale Top part -->
<script type="text/javascript">
var WRInitTime=(new Date()).getTime();
</script>
<!-- ClickTale end of Top part -->
和
<script type='text/javascript'>
// The ClickTale Balkan Tracking Code may be programmatically customized using hooks:
//
// function ClickTalePreRecordingHook() { /* place your customized code here */ }
//
// For details about ClickTale hooks, please consult the wiki page http://wiki.clicktale.com/Article/Customizing_code_version_2
document.write(unescape("%3Cscript%20src='"+
(document.location.protocol=='https:'?
"https://clicktalecdn.sslcs.cdngc.net/www02/ptc/1239e635-ed5c-4c26-81a7-5eedf55952f0.js":
"http://cdn.clicktale.net/www02/ptc/1239e635-ed5c-4c26-81a7-5eedf55952f0.js")+"'%20type='text/javascript'%3E%3C/script%3E"));
</script>
<!-- ClickTale end of Bottom part -->
答案 0 :(得分:2)
我不是100%肯定,你的问题是什么,但如果你想访问与GWT应用程序相同的框架,你需要设置正确的Window对象:
ScriptInjector s= ScriptInjector.fromString("var WRInitTime=(new Date()).getTime();");
s.setWindow(ScriptInjector.TOP_WINDOW);
s.inject();
http://www.gwtproject.org/javadoc/latest/com/google/gwt/core/client/ScriptInjector.FromString.html