问题是,nocache.js文件中的dowcument.write调用仅在文档尚未完成加载时才起作用。否则,document.write将覆盖整个文档。
对于与标记ID添加脚本第一代码:
var script = document.createElement("script");
script.setAttribute("id", markerId);
$doc_0.getElementsByTagName("body")[0].appendChild(script);
对于第二部分(
THEREFOR执行document.write呼叫必须由DOM的方法的createElement被替换几乎在nocache.js的末尾)。与应用程序名称替换了“应用程序”:
try {
var script = document.createElement("script");
script.setAttribute("defer", "defer");
script.innerHTML = "app.onInjectionDone('app')";
$doc_0.getElementsByTagName("body")[0].appendChild(script);
} catch (e) {
// Fallback if we want to use the original html page without embedding in IE
$doc_0.write('<script defer="defer">app.onInjectionDone(\'app\')<\/script>');
}
所以,这是已经在GWT生成的代码要修补的部分。 现在html页面加载和启动应用程序,当用户点击该按钮:
<html>
<head>
<!-- base url -->
<base href="http://localhost:8080/app/" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="static-gwt.css">
<title>APP</title>
<script type="text/javascript">
function startApp() {
if (document.createElement && document.getElementsByTagName) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'app/app.nocache.js';
var heads =document.getElementsByTagName('body');
if (heads && heads[0]) {
heads[0].appendChild(script);
triggerAppStart();
}
}
}
function triggerAppStart(){
try{
app.onInjectionDone('app');
if (!document.createEventObject) {
var evt = document.createEvent("HTMLEvents");
evt.initEvent("DOMContentLoaded", true, true);
document.dispatchEvent(evt);
}
} catch (e) {
window.setTimeout('triggerAppStart()', 100);
}
}
</script>
</head>
<body>
<input type="button" onclick="startApp();return false;">
</body>
</html>
我知道这是不是最好的解决方案,但它只是它的工作到现在为止的方式。
根据应用程序的作用以及您希望如何与Echo2环境交互,您可以将GWT应用程序加载到“iframe”中。 – 2010-04-08 23:15:28