상세 컨텐츠

본문 제목

팝업창이 닫힐때 본창 또는 서버측에정보 넘기기 - ie6, ie7, ie8 사용가능

Programming/javascript

by luckey 2010. 5. 4. 21:54

본문

var alterffourflag=0;
var lastkey=0;
var refreshflag=0;

document.onkeydown = function ( event ) {
   
    event = event || window.event;
    return window_onkeydown();
}

//ie8, ie7 에서는 onbeforeunload에서 잡아준다.(onbeforeunload 후에 onunload가 발생된다.)
window.onbeforeunload = function() {
   
    ie7=navigator.userAgent.toLowerCase().indexOf('msie 7')!=-1;
    ie8=navigator.userAgent.toLowerCase().indexOf('msie 8')!=-1;
   
    if(ie7 || ie8) {
       
        var offset=0.0;
        var width=0.0;
       
        if( document.documentElement && ( document.documentElement.clientWidth )) {

            //IE 6+ in 'standards compliant mode'
            width = document.documentElement.clientWidth;
           
        } else if( document.body && ( document.body.offsetWidth)) {
           
            width=document.body.offsetWidth;
        }

        offset = 40;
        var diff =width-offset;

        if (refreshflag!=1 && width!=0 && window.event.clientY < 0 && window.event.clientX > diff || alterffourflag==1) {

            if( window.opener == null) {                
                //팝업을 열어준 부모창이 없을때 처리할 부분
            }
            else{
                  //팝업을 열어준 부모창이 있을때 처리할 부분
                  opener.location.href="http://www.naver.com";
            }
        }
       
        refreshflag=0;  
    }
}

//ie6에서 onunload이벤트를 잡아서 처리한다.
window.onunload = function() {

    ie7=navigator.userAgent.toLowerCase().indexOf('msie 7')!=-1;
    ie8=navigator.userAgent.toLowerCase().indexOf('msie 8')!=-1;
       
    if(!ie7 || !ie8) {

        if (self.screenTop > 10000 && event.clientY < 0 && event.clientX < 0 || alterffourflag==1) {

            if( window.opener == null) { 
                 //부모창이 없을경우 처리
            }
            else{
               //부모창이 있을경우 처리
                opener.location.href="http://www.naver.com";
            }
        }
    }
}

function window_onkeydown() {

    var keynum
    var numcheck
    e=window.event;
    keynum = e.keyCode;
   
    if(lastkey==18 && keynum==115) { // ||(lastkey==17 && keynum==87)) {

        alterffourflag=1;
    }

    if(keynum==116) {

        refreshflag=1;
    }  
   
    lastkey=keynum;
}

관련글 더보기

댓글 영역