웹마스터 팁

<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... 이라는 메시지를 출력하도록 했습니다.
제목 글쓴이 날짜
텍스트 폼 / 전체선택 하기 자바스크립 mnemosyne 2002.12.24
색다른 링크법(새창) [2] BIRDY™ 2002.12.30
mid 랜덤으로 듣기 ... [2] 아벨라 2003.01.02
숫자를 한글로 변환하는 함수 [1] 행복한고니 2003.01.03
크롬리스에 응용할만한 소스;; [3] MYMob.INT. 2003.01.05
갤러리스킨에 쓰면 좋을 것 같은 미리보기(수정2) [10] 행복한고니 2003.01.06
[re] select form 으로 새 창 띄우기(간단버전) [3] file RedEye 2003.01.27
select form 으로 새 창 띄우기 [4] 당근당근 2003.01.07
홈페이지 패스워드(암호) 걸기 소스 [6] keymove 2003.01.09
혹시 이런것도 될까-_-;;. 시노부 플레이어에서 랜덤 모드 사용자가 택하게 하기 TuTy 2003.01.09
링크가 걸려있는 모든 이미지에 마우스 올리면 서서히 밝아지게 하는 소스입니다. [3] 정해식 2003.01.09
자바스크립트용 계산기 v1.0 [4] 찐군 2003.01.09
[1분짜리 팁!] 홈페이지 입장 여부 묻는 폼 띄우기! [2] 찐군 2003.01.09
IE6SP1 에서 작동하는 크롬리스윈도우!![ByKlein_Chromeless_Window1.0] [13] 술도짱 2003.01.10
1 분마다 배경이 빠뀌는 소스...입니다. [1] q333 2003.01.12
디지털 시계입니다. [8] q333 2003.01.12
성인인증 받는 소스입니다..... [17] q333 2003.01.12
[레드-자바 스크립트초보] 더블클릭하면 경고창 뜬후 사이트 이동하기 [7] 레드 2003.01.17
텍스트 폼에 커서가 미리 깜빡이도록... [8] 카리 2003.01.22
로그인과 로그아웃을 체크하는 방법입니다. [3] 이영호 2003.01.24