본문 바로가기
프로그래밍/JavaScript

[JS] 듀얼모니터 window.open 팝업창 화면 중앙에 배치하기

by joeun 2024. 5. 12.

팝업 javascript 함수

function popup() {
	
    var url="test.do";
    var target="popupTest";
    var popWidth="800";
    var popHeight="580";
	
    var screenX = typeof window.screenX != 'undefined' ? 
    		window.screenX : window.screenLeft,
    	screenY = typeof window.screenY != 'undefined' ? 
        	window.screenY : window.screenTop,
      	outerWidth = typeof window.outerWidth != 'undefined' ? 
        	window.outerWidth : document.documentElement.clientWidth,
      	outerHeight = typeof window.outerHeight != 'undefined' ? 
        	window.outerHeight : document.documentElement.clientHeight-22,
        V = screenX < 0 ? window.screen.width + screenX : screenX,
        left = parseInt(V+(outerWidth-popWidth)/2, 10),
        top = parseInt(screenY + (outerHeight-popHeight)/2.5, 10);
    
    var strOption='';
    strOption+="height="+popHeight;
    strOption+="width="+popWidth;
    strOption+="top="+top;
    strOption+="left="+left;
    
    window.open(url,target,strOption).focus();
}

 

 

 

 

 

👀 참고

https://qastack.kr/programming/4068373/center-a-popup-window-on-screen

 

팝업 창을 화면 중앙에 배치 하시겠습니까?

 

qastack.kr

 

'프로그래밍 > JavaScript' 카테고리의 다른 글

[JS] 일차방정식의 해 구하기  (0) 2022.08.29