IEのブラウザ判定(UA) - manabuyasuda/jquery-plugins GitHub Wiki
//IEの判定 via https://w3g.jp/blog/tools/js_browser_sniffing
var _ua = (function(){
return {
lte_IE6:typeof window.addEventListener == "undefined" && typeof document.documentElement.style.maxHeight == "undefined",
lte_IE7:typeof window.addEventListener == "undefined" && typeof document.querySelectorAll == "undefined",
lte_IE8:typeof window.addEventListener == "undefined" && typeof document.getElementsByClassName == "undefined",
lte_IE9:document.uniqueID && typeof window.matchMedia == "undefined",
gte_IE10:document.uniqueID && window.matchMedia ,
eq_IE8:document.uniqueID && document.documentMode === 8,
eq_IE9:document.uniqueID && document.documentMode === 9,
eq_IE10:document.uniqueID && document.documentMode === 10,
eq_IE11:document.uniqueID && document.documentMode === 11,
// eq_IE10:document.uniqueID && window.matchMedia && document.selection,
// eq_IE11:document.uniqueID && window.matchMedia && !document.selection,
// eq_IE11:document.uniqueID && window.matchMedia && !window.ActiveXObject,
Trident:document.uniqueID
}
})();
VirtualBoxで検証した結果。
/**
* ie8 - IE9以下もしくはIE10
* ie9 - IE9以下もしくはIE10
* ie10 - IE9以下もしくはIE10
* ie11 - それ以外
* edge - それ以外
*/
if(_ua.lte_IE9 || _ua.eq_IE10) {
console.log('_ua.lte_IE9 || _ua.eq_IE10 IE9以下もしくはIE10');
} else {
console.log('それ以外');
}
/**
* IE9 => IE11以上
* IE10 => IE11以上
*/
if(_ua.lte_IE10){
console.log('_ua.lte_IE10 IE10以下');
} else {
console.log('_ua.lte_IE10 IE11以上');
}
/**
* IE9 => IE10以外
* IE10 => IE10
*/
if(_ua.eq_IE10){
console.log('_ua.eq_IE10 IE10');
} else {
console.log('_ua.eq_IE10 IE10以外');
}
/**
* IE9 => IE9以下
* IE10 => IE10以上
*/
if(_ua.lte_IE9){
console.log('_ua.lte_IE9 IE9以下');
} else {
console.log('_ua.lte_IE9 IE10以上');
}