LoginSignup
5
5

More than 5 years have passed since last update.

IE9 での互換表示

Posted at

IE9 はスクロール値の更新頻度が極端に低く(IE7, 8 の 1/3 以下)、パララックスエフェクトなどを使うとガタガタしてしまいどうしようもありません。そこで、IE8 相当の互換モードで表示することにしました。

以下のタグを入れると、IE9 でもドキュメントモードが IE8 になる模様。

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8">

ただし、この meta よりも前に script, link などで外部リソースを読み込んでいるとダメらしいです。
http://subtech.g.hatena.ne.jp/mayuki/20110423/1303554462

また、WordPress のデフォルトテーマや HTML5 Boilterplate のようにコンディショナルタグで html に id をつけたりしてると、うまく互換モードにならない模様。これに頼って CSS や JS を書いていたので、しょうがなく PHP で対応しました。

<!DOCTYPE html>
<?php if (preg_match("/Trident\/5\.0/", $_SERVER['HTTP_USER_AGENT'])): ?>
<html id="ie8" <?php language_attributes(); ?>>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8">
<?php else: ?>
<!--[if IE 6]>
<html id="ie6" <?php language_attributes(); ?>>
<![endif]-->
<!--[if IE 7]>
<html id="ie7" <?php language_attributes(); ?>>
<![endif]-->
<!--[if IE 8]>
<html id="ie8" <?php language_attributes(); ?>>
<![endif]-->
<!--[if IE 9]>
<html id="ie9" <?php language_attributes(); ?>>
<![endif]-->
<!--[if !(IE 6) | !(IE 7) | !(IE 8) | !(IE 9) ]><!-->
<html <?php language_attributes(); ?>>
<!--<![endif]-->
<head>
<?php endif; ?>

これでなんとかなりました。というか、なぜ最初からこれに気づかなかった・・・。

PHP での IE9 の判定

ちなみに IE9 の判定は UA 文字列が /Trident\/5\.0/ にマッチするかでやりました。互換モードでもこの部分は変わらないらしいです。
http://blogs.msdn.com/b/ie/archive/2010/03/23/introducing-ie9-s-user-agent-string.aspx

IE10 では Trident 6.0 になっています。
http://blogs.msdn.com/b/ie/archive/2011/04/15/the-ie10-user-agent-string.aspx

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5