Internet Explorer 11 탐지
IE 11에는 다른 모든 IE와 다른 사용자 에이전트 문자열이 있음을 알고 있습니다.
Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv 11.0) like Gecko
이 질문에 대한 답변이 지정된 IE 11을 감지하려고 시도했습니다. '
Thats !!navigator.userAgent.match(/Trident\/7\./)
하지만 오류가 발생합니다 Object not found and needs to be re-evaluated.
그런 다음 IE11에서 개발자 콘솔을 열고 미리 정의 된 일부 자바 스크립트 개체에 액세스하려고 시도했지만 여전히 동일한 오류가 발생합니다.
나는 시도했다
navigator.userAgent
window.navigator
console.log('test');
누구든지 그것에 대해 알고 있습니까?
2016 년 11 월 18 일 수정
이 코드도 작동합니다 ( ActiveX를 사용하지 않고 다른 솔루션을 선호하는 사용자를 위해 )
var isIE11 = !!window.MSInputMethodContext && !!document.documentMode;
// true on IE11
// false on Edge and other IEs/browsers.
원래 답변
Ie11을 확인하려면 다음을 사용할 수 있습니다.
!(window.ActiveXObject) && "ActiveXObject" in window
IE의 모든 VMS가 있습니다.
주의 : 이것은 IE11에서 작동하지 않습니다.
여기에서 볼 수 있듯이 true를 반환합니다.
그래서 우리가 뭘 할 수 있지 :
분명히 그들은 머신 비트 공간을 추가했습니다.
ie11 :
"Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; rv:11.0) like Gecko"
ie12 :
"Mozilla/5.0 (Windows NT 6.3; Win64; x64; Trident/7.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; rv:11.0) like Gecko"
그래서 우리는 할 수 있습니다 :
/x64|x32/ig.test(window.navigator.userAgent)
이것은 ie11에 대해서만 true를 반환합니다.
MSIE (버전 6에서 11까지)를 빠르게 검색하려면 :
if(navigator.userAgent.indexOf('MSIE')!==-1
|| navigator.appVersion.indexOf('Trident/') > -1){
/* Microsoft Internet Explorer detected in. */
}
위의 모든 답변은 창이나 탐색기가 없다는 사실을 무시합니다. :-)
그런 다음 IE11에서 개발자 콘솔을 열었습니다.
그리고 그것이 말하는 곳입니다
개체를 찾을 수 없으며 다시 평가해야합니다.
네비게이터, 창, 콘솔, 그들 중 아무것도 존재하지 않으며 재평가가 필요합니다. 나는 에뮬레이션에서 그것을 가지고 있습니다. 콘솔을 몇 번 닫고 엽니 다.
IE의 버전 9, 10 및 11을 감지하기 위해 다음 기능을 사용합니다.
function ieVersion() {
var ua = window.navigator.userAgent;
if (ua.indexOf("Trident/7.0") > -1)
return 11;
else if (ua.indexOf("Trident/6.0") > -1)
return 10;
else if (ua.indexOf("Trident/5.0") > -1)
return 9;
else
return 0; // not IE9, 10 or 11
}
그리고 이것을 구현하는 방법
<script type="text/javascript">
!(window.ActiveXObject) && "ActiveXObject"
function isIE11(){
return !!navigator.userAgent.match(/Trident.*rv[ :]*11\./);
}
</script>
This link was helpful . It contains the javascript code to detect all versions of IE up to IE11. I tested the script with IE11 emulator. To find the IE11 emulator, right-click on the web browser click "Inspect element". At the bottom-left of the page, scroll down the navigation bar and click the desktop icon. The "User Agent String" dropdown box contains options to emulate IE6-11.
It works. I just used it some minutes before writing this answer. Cannot post snapshots - not enough reputation.
This is the code - follow the link to view it again:
// Get IE or Edge browser version
var version = detectIE();
if (version === false) {
document.getElementById('result').innerHTML = '<s>IE/Edge</s>';
} else if (version >= 12) {
document.getElementById('result').innerHTML = 'Edge ' + version;
} else {
document.getElementById('result').innerHTML = 'IE ' + version;
}
// add details to debug result
document.getElementById('details').innerHTML = window.navigator.userAgent;
/**
* detect IE
* returns version of IE or false, if browser is not Internet Explorer
*/
function detectIE() {
var ua = window.navigator.userAgent;
// Test values; Uncomment to check result …
// IE 10
// ua = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)';
// IE 11
// ua = 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko';
// Edge 12 (Spartan)
// ua = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0';
// Edge 13
// ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586';
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
// IE 10 or older => return version number
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}
var trident = ua.indexOf('Trident/');
if (trident > 0) {
// IE 11 => return version number
var rv = ua.indexOf('rv:');
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}
var edge = ua.indexOf('Edge/');
if (edge > 0) {
// Edge (IE 12+) => return version number
return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
}
// other browser
return false;
}
@import url(https://fonts.googleapis.com/css?family=Fira+Mono|Fira+Sans:300);
body {
color: black;
background-color: white;
font-family: "Fira Sans", sans-serif;
font-weight: 300;
margin: 0;
padding: 3rem;
}
h1 {
color: darkgrey;
text-align: center;
font-weight: 300;
font-size: 1.5rem;
line-height: 2rem;
}
h2 {
text-align: center;
font-weight: 300;
font-size: 4rem;
}
p {
color: darkgrey;
text-align: center;
font-family: "Fira Mono", monospace;
font-size: 1rem;
line-height: 1.5rem;
}
<h1>Detect IE/Edge version with JavaScript.<br> Updated to recognize Internet Explorer 12+ aka Edge.</h1>
<h2 id="result">detecting…</h2>
<p id="details">n/a</p>
A pretty concise way to detect IE 11 only is this:
if(window.msCrypto) { /* I'm IE11 for sure */ }
or
var IE11= !!window.msCrypto;
msCrypto
is a prefixed version ot the window.crypto
object and only implemented in IE 11.
https://developer.mozilla.org/en-US/docs/Web/API/Window/crypto
좋아, 간단하고 IE11 및 IE 11 버전 이하
browserIsIE = navigator.userAgent.toUpperCase().indexOf("TRIDENT/") != -1 || navigator.userAgent.toUpperCase().indexOf("MSIE") != -1;
navigator.userAgent.toUpperCase().indexOf("TRIDENT/") != -1
IE 11 버전의 navigator.userAgent.toUpperCase().indexOf("MSIE") != -1
경우 IE 11 미만 버전
browserIsIE = navigator.userAgent.toUpperCase().indexOf("TRIDENT/") != -1 || navigator.userAgent.toUpperCase().indexOf("MSIE") != -1;
console.log('Is IE Browser : '+ browserIsIE)
이 RegExp를 사용하면 IE 10 및 IE 11에서 작동하는 것 같습니다.
function isIE(){
return /Trident\/|MSIE/.test(window.navigator.userAgent);
}
나는 이것을 테스트하기 위해 IE 10보다 오래된 IE가 없습니다.
네비게이터 사용 :-
는 navigator
클라이언트 컴퓨터의 브라우저에 대한 모든 정보를 포함하는 객체입니다.
navigator.appName
클라이언트 컴퓨터의 브라우저 이름을 반환합니다.
navigator.appName === 'Microsoft Internet Explorer' || !!(navigator.userAgent.match(/Trident/) || navigator.userAgent.match(/rv:11/)) || (typeof $.browser !== "undefined" && $.browser.msie === 1) ? alert("Please dont use IE.") : alert("This is not IE")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
IE11이 서로 다른 환경에서 둘 이상의 사용자 에이전트 문자열을 제공한다는 것을 알았습니다.
MSIE
및 기타 접근 방식 에 의존하는 대신 Trident
버전 에 의존하는 것이 좋습니다.
const isIE11 = userAgent => userAgent.match(/Trident\/([\d.]+)/) ? +userAgent.match(/Trident\/([\d.]+)/)[1] >= 7;
도움이 되었기를 바랍니다 :)
참고 URL : https://stackoverflow.com/questions/21825157/internet-explorer-11-detection
'developer tip' 카테고리의 다른 글
ASP.NET MVC의 Html.ActionLink에 CSS 클래스를 어떻게 적용합니까? (0) | 2020.08.17 |
---|---|
명령 줄의 스크립트에서 함수를 어떻게 실행할 수 있습니까? (0) | 2020.08.17 |
Visual Studio에서 HTML 태그로 선택 항목을 래핑하려면 어떻게하나요? (0) | 2020.08.17 |
Java가 제네릭을 수정하지 않는다는 점에 왜주의해야합니까? (0) | 2020.08.17 |
Swift에서 완료 핸들러로 함수를 어떻게 만들 수 있습니까? (0) | 2020.08.17 |