問題是,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