I가 내가 실행하고 경고 문 스타일 시트를 사용뿐만 아니라 표시하고 IE의 버전을 확인합니다 다음 스크립트 :이유는 트리거되지 않습니다 IE의 다른 버전을 가지고
var div = document.createElement("div");
div.innerHTML = "<!--[if lte IE 9]><i></i><![endif]-->";
var isIeLessThan9 = (div.getElementsByTagName("i").length == 1);
if (isIeLessThan9) {
alert("<=9");
document.write('<link rel="stylesheet" href="theStyles/defaultStyle_ie.css" type="text/css" charset="utf-8" />');
document.write('<link rel="stylesheet" href="theStyles/captionStyle_ie.css" type="text/css" charset="utf-8" />');
}
if (!isIeLessThan9) {
alert(">9");
document.write('<link rel="stylesheet" href="theStyles/defaultStyle.css" type="text/css" charset="utf-8" />');
document.write('<link rel="stylesheet" href="theStyles/captionStyle.css" type="text/css" charset="utf-8" />');
}
입니다 무슨 일을 IE 버전 10 이상은 >=10
이고 IE 버전 10 미만은 여전히 표시됩니다. >=10
어떻게 해결할 수 있습니까?
편집 :
이이 문제가 해결됩니다 업데이트 된 코드입니다 :
<script type="text/javascript">
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
navigator.sayswho= (function(){
var ua= navigator.userAgent, tem,
M= ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*([\d\.]+)/i) || [];
if(/trident/i.test(M[1])){
tem= /\brv[ :]+(\d+(\.\d+)?)/g.exec(ua) || [];
return 'IE '+(tem[1] || '');
}
M= M[2]? [M[1], M[2]]:[navigator.appName, navigator.appVersion, '-?'];
if((tem= ua.match(/version\/([\.\d]+)/i))!= null) M[2]= tem[1];
return M.join(' ');
})();
var browserversion1 = navigator.sayswho.split(" ");
var browserversion2 = browserversion1[1].split(".")[0].split(",");
var isIeLessThan10 = browserversion1[0] == "IE" && browserversion2[0] < 10;
if (!isMobile.any()) {
if (isIeLessThan10) {
alert("IE<10");
document.write('<link rel="stylesheet" href="theStyles/defaultStyle_ie.css" type="text/css" charset="utf-8" />');
document.write('<link rel="stylesheet" href="theStyles/captionStyle_ie.css" type="text/css" charset="utf-8" />');
}
else {
alert("IE>=10 || !IE");
document.write('<link rel="stylesheet" href="theStyles/defaultStyle.css" type="text/css" charset="utf-8" />');
document.write('<link rel="stylesheet" href="theStyles/captionStyle.css" type="text/css" charset="utf-8" />');
}
}
else {
alert("mobile");
document.write('<link rel="stylesheet" href="theStyles/defaultStyle_mobile.css" type="text/css" charset="utf-8" />');
document.write('<link rel="stylesheet" href="theStyles/captionStyle_mobile.css" type="text/css" charset="utf-8" />');
}
</script>
모두 IE8과 FF는 경고 표시를 IE>=10 || !IE
'getElementsByTagName'과 요소가 일치하지 않으면'length'가'-1'이 아니라'0'이 될 것으로 기대합니다. –
앤서니가 말한 것. 반환 된'NodeList'가 비어 있으면 길이는 0입니다. – Ennui
** 중요 ** _ Internet Explorer 10의 경우 조건부 주석은 더 이상 표준 모드 _에서 지원되지 않습니다. 여기에 관한 모든 것을 읽어보십시오 -> http://msdn.microsoft.com/en-us/library/ms537512.aspx – davidkonrad