차근차근/JAVA Script

ie 버전에 따라 팝업창 띄워주기 | 호환성보기 설정 알아보기

예쁜꽃이피었으면 2015. 9. 9. 09:09


내가 적용한 것 .

<script type="text/javascript">


$(document).ready(function(){

var ver = getInternetExplorerVersion();

var agent = navigator.userAgent.toLowerCase();

if (ver > -1){

if(ver == 7){

var popUrl = "/public/img/popup/msg-ie7.html";//팝업창에 출력될 페이지 URL

var popOption = "width=500, height=469, resizable=no, scrollbars=no, status=no;";    //팝업창 옵션(optoin)

window.open(popUrl,"",popOption);

}

if((ver == 8) && (agent.indexOf('msie 7') > -1 && agent.indexOf('trident') > -1 )){

var popUrl = "/public/img/popup/msg-ie8.html"; //팝업창에 출력될 페이지 URL

var popOption = "width=500, height=611, resizable=no, scrollbars=no, status=no;";    //팝업창 옵션(optoin)

window.open(popUrl,"",popOption);

}

}

else{

}

});


function getInternetExplorerVersion() {

var rv = -1;

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;

</script>





다시 수정

if((ver == 8) && (agent.indexOf('msie 7') > -1 && agent.indexOf('trident') > -1 )){ 

이 부분이 8이면서 호환성 보기가 설정 되있을 때 보여줄 팝업창이라고 생각했는데

8에서 호환성 보기가 설정되어 있으면.. 7 로 인식이 된다.


 <script type="text/javascript">


$(document).ready(function(){

var ver = getInternetExplorerVersion();

var agent = navigator.userAgent.toLowerCase();

if (ver > -1){

if(ver == 7){ // 7 일 때 

var popUrl = "/public/img/popup/msg-ie7.html";//팝업창에 출력될 페이지 URL

var popOption = "width=530, height=490, resizable=no, scrollbars=no, status=no;";    //팝업창 옵션(optoin)

window.open(popUrl,"",popOption);

}

if( agent.indexOf('msie 7') > -1 && agent.indexOf('trident') > -1 ){ // 호환성모드

var popUrl = "/public/img/popup/msg-ie8.html"; //팝업창에 출력될 페이지 URL

var popOption = "width=530, height=615, resizable=no, scrollbars=yes, status=no;"; //팝업창 옵션(optoin)

window.open(popUrl,"",popOption);

}

}

else{

}

});


function getInternetExplorerVersion() {

var rv = -1;

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;

</script>








ie8호환성보기 설정


<script>

        if( /MSIE 7.*Trident/.test( navigator.userAgent ) ) {

            document.getElementsByTagName( "html" )[ 0 ].className += " ie-compatible";

        }

        </script>

        <!-- http://blog.grotesq.com/post/380 -->

         <style type="text/css">

            .is-compatible {

                display: none;

            }

            .ie-compatible .is-compatible {

                display: block;

            }

            .ie-compatible .standard {

                display: none;

            }

        </style>


<!-- include -->

<jsp:include page="/WEB-INF/jsp/common/commonGoodjobHeader.jsp"/>



<body>

        <div class="is-compatible">호환성 보기 동작중

        </div>

        <div class="standard">표준 동작중</div>

    </body>


ie버전 알아내기

<script type="text/javascript">


if( /MSIE 7.*Trident/.test( navigator.userAgent ) ) {

    document.getElementsByTagName( "html" )[ 0 ].className += " ie-compatible";

}



//var agent = navi.userAgent.toLowerCase();


//if( agent.indexOf('msie 7') > -1 && agent.indexOf('trident') > -1 ){

  //호환성모드

//}else{

  //그냥모드

//}




function getInternetExplorerVersion() {

var rv = -1;

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;


function checkVersion() {

var ver = getInternetExplorerVersion();

var agent = navigator.userAgent.toLowerCase();

if (ver > -1){

msg = "You are using Internet Explorer " + ver;

if(ver == 7){

var popUrl = "/public/goodjob/img/popup/msg-ie7.html";

var popOption = "width=500, height=469, resizable=no, scrollbars=no, status=no;";    //팝업창 옵션(optoin)

window.open(popUrl,"",popOption);

}

if((ver == 8) && (agent.indexOf('msie 7') > -1 && agent.indexOf('trident') > -1 )){

var popUrl = "/public/goodjob/img/popup/msg-ie8.html"; //팝업창에 출력될 페이지 URL

var popOption = "width=500, height=611, resizable=no, scrollbars=no, status=no;";    //팝업창 옵션(optoin)

window.open(popUrl,"",popOption);

}

}

else{

msg = "You are not using Internet Explorer";

}

alert(msg);

}

</script>

         <style type="text/css">

            .is-compatible {

                display: none;

            }

            .ie-compatible .is-compatible {

                display: block;

            }

            .ie-compatible .standard {

                display: none;

            }

        </style>

        

<body>

        <div>

        <input type="button" onClick="javascript:getInternetExplorerVersion();">

         <input type="button" onClick="javascript:checkVersion();">

         </div>

         --------------

        <div class="is-compatible">호환성 보기 동작중 </div>

        <div class="standard">표준 동작중</div>

    </body>




반응형