IE6 では動作するが IE8 では動作しないサードパーティの Web アプリケーションがあります。
サンプル コードは次のようになります。「.htc からのメッセージ」メッセージは、IE6 ではポップアップしますが、IE8 ではポップアップしません。
test.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>
<script type='text/javascript'>
//if comment the following line, or move this script in <body>,
//then HTC will work in IE8
document.write ("<h1>document.write() in <head></h1> some calendar codes");
</script>
</head>
<body style='behavior:url(test.htc)'>
HTML Components test
</body>
</html>
test.htc
<script type='text/javascript'>
alert ("message from .htc");
</script>
なぜこれが起こったのですか?これを説明する互換性のあるドキュメントはありますか?
解決
@Quentin が言ったように、またはhttp://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/c1f546f6-d7e1-4b46-a1c9-8f02eaf1286bの別の専門家が言ったように、IE8 はおそらく IE6 と比較して厳密にルールを作成します。 IE8 は、それを破損した HTML ドキュメントとして扱う可能性があります。
そこで、document.createElement
の代わりに を使用して要素を動的に作成し、これらの要素を数秒遅れdocument.write
て DOM に挿入することにしました。いくつかのテストの後、この test.html と実際のアプリケーションの両方で最終的に機能しました。
test-ie8-compatible.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>
<script type='text/javascript'>
function Delay_CreateCalendar()
{
var oContainer = document.createElement ("div");
var oCalendarIFrame = document.createElement ("iframe");
oContainer.appendChild (oCalendarIFrame);
document.body.insertBefore (oContainer);
}
setTimeout (Delay_CreateCalendar, 2000);
</script>
</head>
<body style='behavior:url(test.htc)'>
dhtml HTC 测试
</body>
</html>