웹마스터 팁

<html>
<script>
var imgTmp = new Image();
ns = (document.getElementById && !document.all)?1:0;

function g_resizeWin(){
        var imgsrc, url = document.location.href+"";

        if(url.indexOf('?') > 0){
                imgsrc = url.substring(url.indexOf('?')+1,url.length);
                imgTmp.src = imgsrc;
                imgobj.src= imgsrc;
        }else{
                alert("No Image or incorrect URL");
                self.close();
        }

        imgTmp.onload = new Function("resize()");
}
function resize(){
        var cw = document.body.clientWidth;
        var ch = document.body.clientHeight;
        var sw = screen.width;
        var sh = screen.height;
        var hide = (ns)?document.getElementById("hide"):document.all["hide"];
        var show = (ns)?document.getElementById("show"):document.all["show"];

        hide.style.display = "none";
        show.style.display = "block";

        window.moveTo((sw - imgTmp.width)/2, (sh - imgTmp.height)/2);
        if(imgTmp.width==cw && imgTmp.height==ch) return true;
        window.resizeBy(imgTmp.width-cw, imgTmp.height-ch);
}
</script>
<title>미리보기</title>
<body bgcolor=white topmargin=0 leftmargin=0 marginwidth=0 marginheight=0 onLoad="g_resizeWin()">
<div id=hide>
        <table width=100% height=100%>
                <tr><td align=center style="font-size:9pt">Loading...</td></tr>
        </table>
</div>
<div id=show style="display:none"><a href='javascript:self.close()'><img name=imgobj border=0></a></div>
</body>
</html>

위의 것이 소스구요... 사실 수정할 것은 없습니다. 그냥 새창을 띄워주면서 뒤쪽에 ?그림URL 과 같이 해주시면 됩니다. 예를 들어 위 소스를 저장한 파일이 imgwin.html 이라고 하면 새창을 띄울때 URL에

imgwin.html?http://image.com/images/test.gif 와 같은 식으로 적어주시면 됩니다.

여타 프로그래밍 언어없이 자바스크립트 만으로 구현할 수 있어서 괜찮을 겁니다. -_-;;
혹시 필요할지 몰라서 새창여는 스크립트도 첨부해드립니다.
사용은 openwin("imgwin.html?http://image.com/images/test.gif") 과 같은 식으로 하시면 됩니다.

<script>
function openwin(url){
        window.open(url,"previewWin",'width='+300+',height='+200+',top='+(screen.height-200)/2+',left='+(screen.width-300)/2+',toolbar=no,resizable=no,status=no,scrollbar=no');
}
</script>

P.S//이 늦은 밤 함께 테스트하다가 완성을 못보고 주무신... -_-;; 한상욱님(gallap)에게 감사드립니다.

## 수정내용(2003-01-07)
1. image 객체의 onLoad 이벤트를 사용했습니다.
2. resize() 함수를 한번만 실행하도록 했습니다.
3. 내친김에 화면 딱 중간에 창이 오도록 바꾸었습니다.

## 수정내용(2003-01-08)
1. 일부 이미지의 사이즈 함수가 맞지 않는다는 얘기가 있어서 수정했습니다.
2. 이미지 로딩전에 Loading... 이라는 메시지를 출력하도록 했습니다.