카운터 후 자동 창 닫기

2013. 3. 19. 15:2399. 정리전 - IT/29. IT 잡동지식

 


<html>
<head>
<title>▶건설 ERP System◀</title>
<!-----------------------------------------------------------------------------
  J A V A   S C R I P T   D E C L A R A T I O N
------------------------------------------------------------------------------>
<script language="javascript">
  function f_OnLoad() {
    // X초 뒤에 창닫기
    // (구)startTime();
    setMinute(30); // 단위 : sec(초)
   
    // 깜빡이
    setInterval("startBlink()", 100);
   
    txt_message.value = "국내소스가 반영중입니다\n카운터 완료까지 기다려 주세요";
  }
 
  var varColor = "black";
  function startBlink() {
         if ("black"        == varColor) varColor = "midnightblue";
    else if ("midnightblue" == varColor) varColor = "navy";
    else if ("navy"         == varColor) varColor = "darkblue";
    else if ("darkblue"     == varColor) varColor = "indigo";
    else if ("indigo"       == varColor) varColor = "dimgray";
    else if ("blue"         == varColor) varColor = "dimgray";
    else if ("dimgray"      == varColor) varColor = "gray";
    else if ("gray"         == varColor) varColor = "silver";
    else if ("silver"       == varColor) varColor = "pink";
    else if ("pink"         == varColor) varColor = "black";
    txt_message.style.color = varColor;
  }
 
  //-------------------------------------------------------------------------
  // X초 뒤에 창닫기
  //-------------------------------------------------------------------------
  //카운트 다운 스크립트 시작
  var hhVal = 0;
  var mmVal = 0;
  var ssVal = 0;
  var cFlag = "Y";
  function setMinute(sec){
      cFlag = "Y";
      hdn_minVal.value = sec; // 창닫기 시간(단위:sec)
      txt_hhVal.value="";
      txt_mmVal.value="";
      txt_ssVal.value="";
      var minVal = hdn_minVal.value;
     
      //시간
      if( minVal/60 > 1){
          hhVal =  Math.floor(minVal/60);
          mmVal = (minVal)%60;   
          ssVal = 0;
      //분
      }else{
          mmVal = minVal;
          ssVal = 0;
      }
      setTimeOn();
  }

  function setTimeOn(){
      if(cFlag == "Y"){
          if( ssVal == 0){
              ssVal = 99;
              if(mmVal == 0){
                  hhVal = hhVal - 1;
                  mmVal = 59;
                  if(hhVal == 0)  hhVal = 0;
              }else{
                  mmVal = mmVal - 1;
              }
             
          }else{
              ssVal = ssVal - 1;
          }
          if (hhVal < 10 ) txt_hhVal.value="0"+hhVal;
          else txt_hhVal.value= hhVal;
             
          if (mmVal < 10 ) txt_mmVal.value="0"+mmVal;
          else txt_mmVal.value= mmVal;
             
          if (ssVal < 10 ) txt_ssVal.value="0"+ssVal;
          else txt_ssVal.value= ssVal;
      }
     
      if( cFlag=="N" || (hhVal==0 && mmVal==0 && ssVal==0) ){
          hhVal = 0;
          mmVal = 0;
          ssVal = 0;
          txt_hhVal.value= "00";
          txt_mmVal.value= "00";
          txt_ssVal.value= "00";
          stopTime();
      }else{
          setTimeout("setTimeOn()", 1);//최대 1000초
      }       
  }
  function stopTime(){
      cFlag = "N";
      window.close();
  }
  // 카운트 다운 스크립트 종료
 
 
  // (구)자동창닫기 스크립트
  function startTime(){
    var time= new Date();
    hours= time.getHours();
    mins= time.getMinutes();
    secs= time.getSeconds();
    closeTime=hours*3600+mins*60+secs;
    closeTime+=30;  // This number is how long the window stays open
    Timer();
  }
  function Timer(){
    var time= new Date();
    hours= time.getHours();
    mins= time.getMinutes();
    secs= time.getSeconds();
    curTime=hours*3600+mins*60+secs
    if (curTime>=closeTime) {
      self.close();
    } else {
      window.setTimeout("Timer()",500); //원하는 시간을 입력하세요. 500은 5초
    }
  }
</script>
</head>

<!-----------------------------------------------------------------------------
    D A T A S E T   C O M P O N E N T S   D E C L A R A T I O N
------------------------------------------------------------------------------>

<body onload="f_OnLoad();">
  <div id="div_empty" class="global_button" style="width:305px; height:130px; margin:5px; padding:5px; border:solid 1 red; text-align:center;">
    <table width="100%" height="100%" border=0>
      <tr>
        <td style="text-align:center;">
          <table border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td style="height:20px; font:1.5em; " style="color:red; text-align:center;">▶ 국내 상황실 알림 ◀</td>
            </tr>
            <tr>
              <td style="text-align:center;">
                <input type="hidden" id="hdn_minVal" size="4" maxlength="3" value="" > 
                <input id="txt_hhVal"  value="00" style="width:28px; border:0; background-color:white; font:italic bold 1.2em tahoma,arial,serif; color:darkgray; ">
                <input id="" value=":" style="width:10px; border:0; background-color:white; font:italic bold 1.0em tahoma,arial,serif; color:dimgray; ">
                <input id="txt_mmVal"  value="00" style="width:28px; border:0; background-color:white; font:italic bold 1.2em tahoma,arial,serif; color:darkgray; ">
                <input id="" value=":" style="width:10px; border:0; background-color:white; font:italic bold 1.0em tahoma,arial,serif; color:dimgray; ">
                <input id="txt_ssVal"  value="00" style="width:28px; border:0; background-color:white; font:italic bold 1.2em tahoma,arial,serif; color:darkgray; ">
              </td>
            </tr>
            <tr>
              <td style="text-align:center; font:0.45em tahoma,arial,serif; color:gray; ">시간이 00:00:00 될때까지 기다리는 겁니다</td>
            </tr>
            <tr>
              <td>
                <textarea id="txt_message" style="width:285px; height:52px; padding:5px; color:blue; font:italic bold 17px arial,serif; text-align:center;"></textarea>
              </td>
            </tr>
          </table>
        </td>
      </tr>          
    </table>         
  </div>
   
</body>
</html>

 

 

원문소스

<html>
<script language="JavaScript">
<!-- 
function clock() {
   var time = new Date()
       
   var hour = time.getHours()
   var minute = time.getMinutes()
   var second = time.getSeconds()
   var store = " " 
       
   store += ((hour > 12) ? (hour - 12) : hour)
   store += ((minute < 10) ? ":0" : ":") + minute
   store += ((second < 10) ? ":0" : ":") + second
   store += (hour >= 12) ? " P.M" : " A.M"
       
   document.time.clock.value = store    
   setTimeout("clock()", 1000)
}

//카운트 다운 스크립트 시작
var hhVal = 0;
var mmVal = 0;
var ssVal = 0;
var cFlag = "Y";
function setMinute(){
    cFlag = "Y";
    document.tForm.hhVal.value="";
    document.tForm.mmVal.value="";
    document.tForm.ssVal.value="";
   
    var minVal = document.tForm.minVal.value;
   
    //시간
    if( minVal/60 > 1){
        hhVal =  Math.floor(minVal/60);
        mmVal = (minVal)%60;   
         ssVal = 0;
    //분
    }else{
        mmVal = minVal;
        ssVal = 0;
   
    }
    setTimeOn();
}

function setTimeOn(){
  
    if(cFlag == "Y"){
      
        if( ssVal == 0){
           
            ssVal = 59;
            if(mmVal == 0){
                hhVal = hhVal - 1;
                mmVal = 59;
                if(hhVal == 0)  hhVal = 0;
            }else{
                mmVal = mmVal - 1;
            }
           
        }else{
            ssVal = ssVal - 1;
        }
        if (hhVal < 10 ) document.tForm.hhVal.value="0"+hhVal;
        else document.tForm.hhVal.value= hhVal;
           
        if (mmVal < 10 ) document.tForm.mmVal.value="0"+mmVal;
        else document.tForm.mmVal.value= mmVal;
           
        if (ssVal < 10 ) document.tForm.ssVal.value="0"+ssVal;
        else document.tForm.ssVal.value= ssVal;
    }
   
    if( cFlag=="N" || (hhVal==0 && mmVal==0 && ssVal==0) ){
        hhVal = 0;
        mmVal = 0;
        ssVal = 0;
        document.tForm.hhVal.value= "00";
        document.tForm.mmVal.value= "00";
        document.tForm.ssVal.value= "00";
        stopTime ();
    }else{
        setTimeout("setTimeOn()", 1);//최대 1000초
    }       
}
function stopTime (){
    cFlag = "N";
    alert("완료");
}
//카운트 다운 스크립트 종료
//-->
</script>
</head>
<body onLoad="clock()">
   <form name="time">
       현재 시간 : <input name="clock" size="12" value="" style="border:0">
   </form>
   <form name="tForm">
       카운트할 시간(분 단위) 입력:<input name="minVal" size="4" maxlength="3" value="" > 
       <input type="button"   value="카운트시작" onClick="javascript:setMinute()" />
       <input name="hhVal" size="4" value="00" style="border:0">:<input name="mmVal" size="4" value="00" style="border:0">:<input name="ssVal" size="4" value="00" style="border:0">  
   </form>
   <form name="sForm">
        카운종료 <input type="button"  value="카운트 종료"  onClick="javascript:stopTime()">
    </form>
</body>
</html>