본문 바로가기
프로그래밍/html & jsp

팝업창 중앙으로 위치

by Super User 2010. 9. 15.
// 팝업창 중앙으로 위치
function center(){
    var x,y;
    if (self.innerHeight) { // IE 외 모든 브라우저
        x = (screen.availWidth - self.innerWidth) / 2;
        y = (screen.availHeight - self.innerHeight) / 2;
    }else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict 모드
        x = (screen.availWidth - document.documentElement.clientWidth) / 2;
        y = (screen.availHeight - document.documentElement.clientHeight) / 2;
    }else if (document.body) { // 다른 IE 브라우저( IE < 6)
        x = (screen.availWidth - document.body.clientWidth) / 2;
        y = (screen.availHeight - document.body.clientHeight) / 2;
    }
    window.moveTo(x,y);
}

팝업 파일의 마지막 하단에
<script type="text/javascript" language="JavaScript">
<!--
center();
//-->
</script>

* 공용 스크립트 common.js 등의 파일에 넣어두고 사용하면 편합니다.
* 직접 확인한 바로는 IE/FF/NS5~7/오페라 등에서 모두 적용됨을 확인할 수 있었습니다.

출처 : http://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=45793&page=1

'프로그래밍 > html & jsp' 카테고리의 다른 글

CSS핵  (0) 2010.10.29
pre 태그 강제 줄바꿈  (0) 2010.09.29
HTML 윈도우창 닫힐때 발생하는 이벤트  (0) 2010.08.27
tinymce 에디터 사용법  (0) 2010.08.10
<PRE> 태그 길이 고정  (0) 2010.08.06