現在の Web ブラウザが IE であるかどうかを検出するために使用されていた一部のレガシー コードを壊しているIE10 以降、条件付きコメントは廃止されました。https://gist.github.com/padolsey/527683を参照してください
Internet Explorer のすべてのバージョン (IE9 以下だけでなく) で機能するソリューションを探しています。
ありがとう
現在の Web ブラウザが IE であるかどうかを検出するために使用されていた一部のレガシー コードを壊しているIE10 以降、条件付きコメントは廃止されました。https://gist.github.com/padolsey/527683を参照してください
Internet Explorer のすべてのバージョン (IE9 以下だけでなく) で機能するソリューションを探しています。
ありがとう
https://gist.github.com/padolsey/527683の「ecstaticpeon」からのコメントに従って、これが機能することがわかりました。
http://jsfiddle.net/P5z4N/4/で自分で試してみてください
var ie_version = (function() {
var undef,
v = 3,
div = document.createElement('div'),
all = div.getElementsByTagName('i');
while (
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
all[0]
);
return v > 4 ? v : undef;
}());
/*@cc_on
if (typeof(ie_version) == 'undefined') {
ie_version = parseInt(@_jscript_version);
}
@*/
以下の JavaScript も機能するようです。
http://jsfiddle.net/e8G3S/1/で試してみてください
// Returns the version of Internet Explorer or a -1 (indicating the use of another browser)
function getInternetExplorerVersion(){
var rv = -1; // Return value assumes failure.
if (navigator.appName == 'Microsoft Internet Explorer'){
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat( RegExp.$1 );
}
return rv;
}
function displayAlert(){
var msg = "You're not using Internet Explorer.";
var ver = getInternetExplorerVersion();
if ( ver > -1 ){
if ( ver <= 8.0 ){
msg = "You're using Internet Explorer 8 or below" ;
}
else if ( ver >= 9.0 && ver < 10.0 ){
msg = "You're using IE 9 or above";
}
else{
msg = "You're using IE 10 or above";
}
}
alert( msg );