메인메뉴 바로가기

HOME으로 가기


Tip&Tech 브라우저 체크 (Bowser Check)

페이지 정보

profile_image
작성자 너갱이
댓글 2건 조회 105,973회 작성일 15-05-15 14:05

본문

<!--[if !IE]><p>Internet Explorer가 아닙니다.</p><![endif]-->

<!--[if IE]><p>Internet Explorer 입니다.</p><![endif]-->
 
<!--[if IE 5.0]><p>Internet Explorer Version 5.0 입니다.</p><![endif]-->
<!--[if IE 5.5]><p>Internet Explorer Version 5.5 입니다.</p><![endif]-->
<!--[if IE 6]><p>Internet Explorer Version 6 입니다.</p><![endif]-->
<!--[if IE 7]><p>Internet Explorer Version 7 입니다.</p><![endif]-->
 
<!--[if gt IE 7]><p>IE7 초과 유저에게만 표시할 내용 (7제외)</p><![endif]-->
<!--[if gte IE 7]><p>IE7 이상 유저에게만 표시할 내용 (7포함)</p><![endif]-->
<!--[if lt IE 7]><p>IE7 미만 유저에게만 표시할 내용 (7제외)</p><![endif]-->
<!--[if lte IE 7]><p>IE7 이하 유저에게만 표시할 내용 (7포함)</p><![endif]-->
 
<< window.navigator.userAgent >>
크롬 : Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36 
사파리 : Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2
파이어폭스 : Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0
오페라 : Opera/9.80 (Windows NT 6.1; WOW64) Presto/2.12.388 Version/12.16
 
익스플로러 11 : Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2; rv:11.0) like Gecko
익스플로러 10 : Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2)
익스플로러 9 : Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2)
익스플로러 8 : Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2)
익스플로러 7 : Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2)
익스플로러 5 : Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2)
 
익스플로러 10 (사용자에이전트 문자열) : Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0) 
익스플로러 9 (사용자에이전트 문자열) : Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
익스플로러 8 (사용자에이전트 문자열) Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)
익스플로러 7 (사용자에이전트 문자열) : ​Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)
익스플로러 6 (사용자에이전트 문자열) : ​Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
 
 
//조건 예문
if(window.navigator.userAgent.indexOf("MSIE") > -1 || window.navigator.userAgent.indexOf("Trident") > -1) {
          //익스플로러이면 실행
}
 
if(window.navigator.userAgent.indexOf("MSIE 6") > -1) {
          //익스플로러 6이면 실행
}
 
//브라우저명 찾기
var getBrowser = function(){
    var agent = window.navigator.userAgent;
    
    //MSIE
    if( agent.match("MSIE") || agent.match("Trident") ){
       return "MSIE";
    }else if( agent.match("Chrome") ){
       return "Chrome";
    }else if( agent.match("Safari") ){
       return "Safari";
    }else if( agent.match("Firefox") ){
       return "Firefox";
    }else if( agent.match("Opera") ){
       return "Opera";
    }else{
       return "Other";
    }
}
alert(getBrowser());
 

} 

댓글목록

profile_image

너갱이님의 댓글

너갱이 작성일

우선 브라우저 체크

useragnet 값 얻어와서 브라우저 문자열 검색.

참고로 indexOf는 파라미터 문자열이 해당 문자열에 포함되어있지않을경우 '-1'을 리턴함.
포함되었을 경우에는 해당 위치(시작점- 0부터표시)

var agt = navigator.userAgent.toLowerCase();
if (agt.indexOf("chrome") != -1) return 'Chrome';
if (agt.indexOf("opera") != -1) return 'Opera';
if (agt.indexOf("staroffice") != -1) return 'Star Office';
if (agt.indexOf("webtv") != -1) return 'WebTV';
if (agt.indexOf("beonex") != -1) return 'Beonex';
if (agt.indexOf("chimera") != -1) return 'Chimera';
if (agt.indexOf("netpositive") != -1) return 'NetPositive';
if (agt.indexOf("phoenix") != -1) return 'Phoenix';
if (agt.indexOf("firefox") != -1) return 'Firefox';
if (agt.indexOf("safari") != -1) return 'Safari';
if (agt.indexOf("skipstone") != -1) return 'SkipStone';
if (agt.indexOf("msie") != -1) return 'Internet Explorer';
if (agt.indexOf("netscape") != -1) return 'Netscape';
if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';



이번엔 IE 버전체크

같은 화면인데, ie8에서는 되고, ie9이상 에서는 안되고.. 뭐 이런경우가 생겨버렸다. xp와 win7의 OS 문제일 수도 있을것 같긴 한데, 테스트를 제대로 해볼 수 가 없는 환경이라 일단 IE 버전체크 하는걸로 해결ㅋ.

보통 익스플로러의 useragnt 값은 이런식으로 나오는데,

msie 8.0; windows nt 5.1; trident/4.0;  ......

위의 경우처럼 'msie 8.0' 이라고 버전까지 나와있어서,
저부분만 뽑아내면 된다.

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;
    }

이러면 rv값에 '8' 이 리턴됨.

그런데 간혹.
IE 8 이상에서도 'msie 7.0' 이라고 나오는 경우가 있다. (호환성보기 사용)
그렇게 되면 'msie 7.0' 만 가지고는
이놈이 7,8,9,10 중에 어떤놈인지 확인이 불가능하다.

그런데 이럴때도 7,8,9,10 같에 차이는 있다.

mise 뒤쪽에 trident/4.0; 이 부분으로 식별하면 된다.

8버전 이상의 trident 값은 아래와 같다.
7이하의 버전에서는 trident 값이 없다.

IE 8 = trident/4.0
IE 9 = trident/5.0
IE 10 = trident/6.0


trident 값 체크 t


var trident = navigator.userAgent.match(/Trident\/(\d)/i);
if(trident != null){
    return 1;
} else{
    return 0;
}



IE 테스트 해보고 싶을때는
morder.IE (http://www.modern.ie/ko ) 여기도 좋음

왜 IE에서 에러나는지 친절하게 알려줌.

profile_image

너갱이님의 댓글

너갱이 작성일

IE 테스트 해보고 싶을때는
morder.IE (http://www.modern.ie/ko ) 여기도 좋음

왜 IE에서 에러나는지 친절하게 알려줌.