問題は、nocache.jsファイルのdowcument.write呼び出しが、ドキュメントのロードが完了していない場合にのみ機能することです。それ以外の場合、document.writeはドキュメント全体を上書きします。
そのため、document.write呼び出しは、DOMのcreateElementメソッドに置き換える必要があります。
マーカーIDを使用してスクリプトを追加する最初のコードの場合:
var script = document.createElement("script");
script.setAttribute("id", markerId);
$doc_0.getElementsByTagName("body")[0].appendChild(script);
2番目の部分(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>
これが最善の解決策ではないことは知っていますが、これまでのところ、これが唯一の方法です。