블로그 이미지
자료에 문제가 있을 경우, 확인하는대로 삭제처리 하겠습니다. 즐거운 하루 되시길...
05-04 18:45
Total
Today
Yesterday

카테고리

분류 전체보기 (199)
이야기방 (20)
공부방 (173)
개발노트&관련잡다구니 (6)

'자바스크립트'에 해당되는 글 23건

  1. 2009.07.23 [자바스크립트] 화면중앙에 새창뛰우기
  2. 2009.07.23 [자바스크립트] 확장자 검사하기

이 소스는 src를 받아서 크기에 따라서 (width가 600이상과 이하) 에 따라서 화면의 가운데에서 이미지를 출력하고 이미지를 출력 할 경우에 종료됍니다.

 

<script language="JavaScript">

 var imgObj = new Image();
 var winl, wint, setCetner;
 
 function showImgWin(src) {//출력할 주소
  imgObj.src = src;
  //alert("width : "+ imgObj.width)
  setTimeout("createImgWin(imgObj)", 100);
 }
 function createImgWin(imgObj) {
  if (! imgObj.complete) {
   setTimeout("createImgWin(imgObj)", 100);
   return;
  }
  
  if ( imgObj.width <600){ // 이미지의 width에 따른 분기문
   alert("600이하  width : "+ imgObj.width+" height : " + imgObj.height);

   //화면 중앙에 배치
   winl= (screen.width-imgObj.width)/2;
   wint= (screen.height-imgObj.height)/2;
   

  //setCenter라는 곳에 설정값들을 저장한다.
   setCenter = 'width=' + imgObj.width + ', height=' + imgObj.height+ ', ';
   setCenter += 'top='+wint+', ';
   setCenter += 'left='+winl+', ';
   setCenter += 'resizable=yes';
   
   alert(setCenter);
   

//설정되어진 값으로 새창을 생성한다.
   var imageWin = window.open("", "imageWin", setCenter);
   imageWin.document.write("<html><body style='margin:0'>");

//a tag를 이용해서 클릭시 창닫기 기능을 만든다.
   imageWin.document.write("<a href='javascript:window.close()'><img src='" + imgObj.src + "' width=" + imgObj.width + ",height=" + imgObj.height+" ='javascript:imageWin.self.close();'></a>");
   imageWin.document.write("</body><html>");
   imageWin.document.title = imgObj.src;
   
  } else {   
   var t_height= (imgObj.height*600) / imgObj.width;
   winl= (screen.width-imgObj.width)/2;
   wint= (screen.height-t_height)/2;
   setCenter = 'width=600, height=' + t_height+ ', ';
   setCenter += 'top='+wint+', ';
   setCenter += 'left='+winl+', ';
   setCenter += 'resizable=yes';;
   
   alert("600이상 width : "+ imgObj.width+" height : " + t_height);
   alert(setCenter); 
    
   var imageWin = window.open("", "imageWin", setCenter);
   imageWin.document.write("<html><body style='margin:0'>");
   imageWin.document.write("<a href='javascript:window.close()'><img src='" + imgObj.src + "' width=600, height="+t_height+" ='javascript:imageWin.self.close();'></a>");
   imageWin.document.write("</body><html>");
   imageWin.document.title = imgObj.src;     
  } 
 }

</script>


Posted by 래채
, |
<script type="text/javascript">


function filechk(){

 f= document.inputForm; 
 existExt = ".jpg,.gif,.jpeg"; //검사할 파일의 확장자
 existExtArray = existExt.split(",");  //,로 나누어서 배열 초기화
 TempAttfile = new Array();
 var checkFlag;
  //여러개의 파일을 받아서 검사 할 경우
 TempAttfile[0] = f.attfile1.value;
 TempAttfile[1] = f.attfile2.value;
 TempAttfile[2] = f.attfile3.value;
 TempAttfile[3] = f.attfile4.value;
 TempAttfile[4] = f.attfile5.value;
 //첫번째 for문은 파일의 순서

 //두번째 for문은 해당파일의 확장자를 검사
 for(i=0; i < TempAttfile.length ; i++){
  if (TempAttfile[i] != "") {
   checkFlag = "false";
      Temp_strExt1_num = TempAttfile[i].slice(TempAttfile[i].indexOf(".")).toLowerCase();
      for (j=0; j < existExtArray.length; j++){
          if (Temp_strExt1_num == existExtArray[j]){

                //해당파일의 확장자가 검사할확장자에 있을경우 flag를 true로 변환하면 적합하다는것을 알린다.
              checkFlag = "true";
          }
      }           
      if (checkFlag == "false"){
       tmpnum = i+1; //경고창 순서를 출력할 순서를 임시로저장
       alert('[['+tmpnum+']]번째 파일은 등록하실 수 없는 확장자 입니다.');
             return;      
      } else {
       continue;
      }    
  } else {
   continue;
  }
 }

  
 f.submit();
}

</script>


Posted by 래채
, |