본문 바로가기
Web Programing!/Script

[SCRIPT] 팝업 자동 리사이즈

by 어설픈봉봉이 2011. 9. 13.
반응형
SMALL





/*
   * 팝업 자동 리사이징
   *  - 윈도 환경에 따라 사이즈가 다를 수 있습니다.
   *  - 팝업페이지의 스크립트 최하단에서 실행하십시오.
   *
   * (ex.) window.onload = function(){popupAutoResize();}
  */

  function popupAutoResize() {

      var thisX = parseInt(document.body.scrollWidth);
      var thisY = parseInt(document.body.scrollHeight);
      var maxThisX = screen.width - 50;
      var maxThisY = screen.height - 50;
      var marginY = 0;
      alert(thisX + "===" + thisY+ "===" +maxThisX );
      //alert("임시 브라우저 확인 : " + navigator.userAgent);
      // 브라우저별 높이 조절. (표준 창 하에서 조절해 주십시오.)
      if (navigator.userAgent.indexOf("MSIE 6") > 0) marginY = 45;        // IE 6.x
      else if(navigator.userAgent.indexOf("MSIE 7") > 0) marginY = 75;    // IE 7.x
      else if(navigator.userAgent.indexOf("Firefox") > 0) marginY = 50;   // FF
      else if(navigator.userAgent.indexOf("Opera") > 0) marginY = 30;     // Opera
      else if(navigator.userAgent.indexOf("Netscape") > 0) marginY = -2;  // Netscape

      if (thisX > maxThisX) {
          window.document.body.scroll = "yes";
          thisX = maxThisX;
      }

      if (thisY > maxThisY - marginY) {
          window.document.body.scroll = "yes";
          thisX += 19;
          thisY = maxThisY - marginY;
      }

      window.resizeTo(thisX+10, thisY+marginY);

      // 센터 정렬
      // var windowX = (screen.width - (thisX+10))/2;
      // var windowY = (screen.height - (thisY+marginY))/2 - 20;
      // window.moveTo(windowX,windowY);

  }


반응형