どのブラウザーに応じて、使用している IE のバージョンを見つけて、body タグにクラスを追加しようとしています。
私が持っているコードは
if (navigator.appName == "Microsoft Internet Explorer") {
//Set IE as true
ie = true;
//Create a user agent var
var ua = navigator.userAgent;
//Write a new regEx to find the version number
var re = new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})");
//If the regEx through the userAgent is not null
if (re.exec(ua) != null) {
//Set the IE version
ieVersion = parseInt(RegExp.$1);
}
}
else {
ie = false;
}
function ieTag() {
if (ie == true) {
if (ieVersion == 7) {
$('body').addClass('IE7');
}
}
if (ie == true) {
if (ieVersion == 8) {
$('body').addClass('IE8');
}
}
if (ie == true) {
if (ieVersion == 9) {
$('body').addClass('IE9');
}
}
}
そして私はこれを使って関数を呼び出しています
<script type="text/javascript">
$(document).ready(function () {
//IE Version Control
ieTag();
});
</script>
しかし、私は何らかの理由で IE 9 だけを使用しています。このスクリプトは以前に動作していたので、何が問題なのか本当にわかりません!!!
私もこのスクリプトを使用してみました
function ieTag() {
if (ie == true) {
$('body').addClass('IE' + ieVersion);
}
}
しかし、まだIE9のみをピックアップしています
私は IE( と開発者ツールを使用してバージョンを変更しています (これらのスクリプトは両方とも以前に作業していました)。