Web

브라우저 버전체크 - IE Conditional Comments 필터링

알콜뭉뭉이 2017. 6. 1. 09:35
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

W3C의 규격에 의거하여 CSS 코드를 작성하더라도, 각각의 웹 브라우저마다 웹 페이지가 다르게 출력되는 문제가 있습니다. 이러한 문제는 브라우저들이 CSS 규격을 조금씩 서로 다르게 해석하고 출력할 뿐더러, 몇몇 규격은 전혀 출력하지 못하기 때문에 발생합니다.

이처럼 브라우저가 CSS를 W3C 규격과 다르게 출력하거나, 전혀 출력하지 못하는 문제를 CSS 출력 버그(CSS Rendering Bug)라고 합니다. CSS 출력 버그는 표준을 준수하여 웹 페이지를 제작할 때 가장 큰 걸림돌이 됩니다. W3C 규격 외에도 각각의 웹 브라우저들의 CSS 출력 현황에 대해서도 이해해야 하며, 이러한 버그들을 잡는 방법까지 파악해야 하기 때문입니다.

IE7, FF1~2, Opera9, Safari처럼 최근에 출시된 웹 브라우저들은 W3C 규격에 맞춰서 CSS를 출력합니다. 문제는 IE6, NN7 이하의 오래된 브라우저들이죠. 특히 높은 브라우저 시장 점유율을 기록중인 IE6 브라우저의 CSS 출력 버그들이 큰 문제입니다.

이러한 CSS 출력 버그들을 CSS Hack과 Filtering으로 대처할 수 있습니다. 예전에는 CSS Hack을 많이 사용했으나, IE7이 출시된 이후로는 CSS Filtering을 주로 사용합니다. 특히 사용이 간단하고 MS에서 추천하는 방법인 IE Conditional Comments Filtering(IE CC-필터링)을 가장 많이 사용합니다.

자세히 보시면 보통의 HTML 주석문 에서 조금 추가된 형태라는 걸 알수 있겠죠?
if 조건문이 참이면 안의 내용이 유효하다는 뜻입니다. 즉 주석으로 처리되지 않고
화면에 나타나거나 실행됩니다. 반대로 조건에 맞지 않으면 그냥 주석으로 처리되겠죠.

IE 5.0 이상에서만 작동합니다. 5.0 미만의 버전에서는 그냥 주석으로 인식합니다.


활용예
<!--[if IE]>You are using Internet Explorer.<![endif]-->
<![if !IE]>You are not using Internet Explorer.<![endif]>

<!--[if IE 7]>Welcome to Internet Explorer 7!<![endif]-->
<!--[if !(IE 7)]>You are not using version 7.<![endif]-->

<!--[if gte IE 7]>You are using IE 7 or greater.<![endif]-->
<!--[if (IE 5)]>You are using IE 5 (any version).<![endif]-->
<!--[if (gte IE 5.5)&(lt IE 7)]>You are using IE 5.5 or IE 6.<![endif]-->
<!--[if lt IE 5.5]>Please upgrade your version of Internet Explorer.<![endif]-->

<!--[if true]>You are using an <em>uplevel</em> browser.<![endif]-->
<![if false]>You are using a <em>downlevel</em> browser.<![endif]>

<!--[if true]><![if IE 7]>This nested comment is displayed in IE 7. <![endif]><![endif]-->


조건문에 사용할 수 있는 요소

ItemExampleComment
IE[if IE]The only currently supported feature is the string "IE", corresponding to Internet Explorer.
value[if IE 7]An integer or floating point numeral corresponding to the version of the browser. Returns a Boolean value of true if the version number matches the browser version. For more information, see Version Vectors.
![if !IE]The NOT operator. This is placed immediately in front of the featureoperator, or subexpression to reverse the Boolean meaning of the expression.
lt[if lt IE 5.5]The less-than operator. Returns true if the first argument is less than the second argument.
lte[if lte IE 6]The less-than or equal operator. Returns true if the first argument is less than or equal to the second argument.
gt[if gt IE 5]The greater-than operator. Returns true if the first argument is greater than the second argument.
gte[if gte IE 7]The greater-than or equal operator. Returns true if the first argument is greater than or equal to the second argument.
( )[if !(IE 7)]Subexpression operators. Used in conjunction with boolean operators to create more complex expressions.
&[if (gt IE 5)&(lt IE 7)]The AND operator. Returns true if all subexpressions evaluate to true
|[if (IE 6)|(IE 7)]The OR operator. Returns true if any of the subexpressions evaluates to true.
true[if true]Always evaluates to true.
false[if false]Always evaluates to false.



참고자료
http://msdn.microsoft.com/en-us/library/ms537512.aspx 
http://hooney.net/2007/08/27/451/ 
http://www.quirksmode.org/css/condcom.html






'Web' 카테고리의 다른 글

div 이미지 공백 없애기  (0) 2017.06.02
구글 검색결과 순위 결정요인  (0) 2017.06.01
글꼴의 단위에 따른 크기 비교표  (0) 2017.06.01
주민등록번호 체크 알고리즘  (0) 2017.05.31
W3C P3P 규약설정  (0) 2017.05.31