不可解な問題があります: この一見単純なページは IE9 では動作しません:
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<!-- jq.js is the non-minified jQuery library -->
<script type="text/javascript" src="jq.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('body').append('<h1>ok</h1>');
});
</script>
</head>
<body>
</body>
</html>
私が得た動作は、ページに「OK」と表示されることもあれば、何も表示されないこともあります。コンピューターの速度に依存することがわかりました。高速なコンピューターを使用している場合、通常は機能しますが、低速のコンピューターでは、3 回中 2 回ほど失敗します。
デバッグ コンソールを見ると、jQuery にアクセスしようとするとアクセス許可が拒否されるという症状がありますnavigator.userAgent
。
quirks
ブラウザーは、モードからモードに切り替えていることを (ログに) 書き込みIE9
ます。私の仮説は、ブラウザーがモードに切り替わる前に jQuery がロードされているため、jQuery がIE9
モードに引っ掛かり、quirks
そこからブラウザーの属性にアクセスできなくなるというものです。
IE9をすぐにモードに切り替えるためにメタタグ<!doctype html>
を挿入して挿入しようとしましたが、問題は解決しませんでした。X-UA-Compatible
IE9
jQuery を省略して、この単純なスニペットで問題を再現することができました。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
</head>
<body>
<script type="text/javascript">
document.write('<h1>testing</h1>');
try {
document.write('<h1>' + navigator.userAgent + '</h1>');
document.write('<h1>ok</h1>');
} catch(e) {
document.write('<h1>not ok</h1>');
}
</script>
</body>
</html>
( http://test.m.e17.dk/ie9-navigator/で入手できます。)
次の方法で再現します。
- ページを開きます。
- F5 を押します。
- カーソルをアドレスバーに置きます。
- 入力を押します。
ステップ 2 ~ 4 を必要なだけ繰り返します。DOM が読み込まれるのを待たなかったことが原因で問題が発生した可能性があります ( http://bugs.jquery.com/ticket/12282で説明されているように)。