참조..
http://gonnie.tistory.com/entry/%EC%9E%90%EB%B0%94%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%EC%9E%90%EC%8B%9D%EC%B0%BD%EC%97%90%EC%84%9C-%EB%B6%80%EB%A7%88%EC%B0%BD-%ED%95%A8%EC%88%98%EC%A0%9C%EC%96%B4

원래 페이지에 상세설명 잘 되어있어요~~~.

 

[자바스크립트]자식창에서 부모창의 함수제어
프로그래밍/Java Script
먼저 부모창에 function test(){}이라는 함수가 있다고 가정한다.
1)팝업창일경우
opener.test();

2)iframe일경우
parent.test();
와 같이 호출하면 된다. (무지쉽지?)

3) 부모창에서 iframe내 함수접근
   var ifr = document.getElementById('iframeID');
    ifr.contentWindow.function_name();
부모창에서 'iframeID'이라는 iFrame에 지정된 페이지의 function_name()함수에 접근하는 방법이다.

4) <a href='www.url.com' target='_parent'>link</a>으로 지정해도 됨. 물론 자바스크립트를 제어하는 것은 아니라서
     parent.location.href='www.url.com';과 동일한 효과만 볼수 있음. 페이지 이동에 국한하여 사용할 수 있는 태그이다.
     기초적이고 간단한 것인데 종종 잊어먹곤 하니 유의할 것.

Posted by 말없제이
,

pop 으로 띄운 child 가 parent 값을 읽지 못할 때
분류없음 2007/09/05 20:20
opener.document.formName.inputName.value 를 읽어오려는데
에러가 난다.
IE 창을 보니 '액세수가 거부되었습니다' 라는 에러 메시지가 나온다.
(firebug 에서는 uncaught exception: HTMLDocument.formName 1)

30 분 정도면 고칠 수 있을 줄 알았는데 결국 4 시간만에 찾았다.
parent 쪽에서 domain 을 다시 할당하고 있었다.
(

if(document.domain.toString().indexOf("x1test.co.kr") != -1) document.domain="x1test.co.kr"; else document.domain="x1.co.kr";
)
이럴 때는 child 쪽에서도 위 스크립트를 다시 반복해주면 된다.

--> domain 시 현재가 하위단에 있을경우 상위단 도메인을 정의할수 있다.
안되는 경우 1. Localhost로 작업하는데. Daum을 호출할경우 에러.

Posted by 말없제이
,

년도 구하고 윤달구해야 한다고 복잡하게 생각했는데..  그냥 0일로 넣으면 월의 마지막날이 나옴 - -

<script>
alert(new Date('2012','03','0').getDate());
alert(new Date('2012','02','0'));
</script>
<html>
<head></head>
<body>
<input type="text"
<input id="txtNo" type="password" style="display:none;" />
<script>
 alert(document.getElementById("txtNo").value);
</script>
</body>
</html>

 

Posted by 말없제이
,
SelectBox Item(셀렉터박스) 아이템

<html>
<head>
 <title>http://www.blueb.co.kr</title>


<SCRIPT LANGUAGE="JavaScript">
<!--
function move(fbox,tbox) {
 var i = 0;
 if(fbox.value != "") {
 var no = new Option();
  no.value = fbox.value;
  no.text = fbox.value;
  tbox.options[tbox.options.length] = no;
  fbox.value = "";
   }
}
function remove(box) {
 for(var i=0; i<box.options.length; i++) {
 if(box.options[i].selected && box.options[i] != "") {
  box.options[i].value = "";
  box.options[i].text = "";
    }
 }
 BumpUp(box);
}
function BumpUp(abox) {
 for(var i = 0; i < abox.options.length; i++) {
 if(abox.options[i].value == "")  {
 for(var j = i; j < abox.options.length - 1; j++)  {
  abox.options[j].value = abox.options[j + 1].value;
  abox.options[j].text = abox.options[j + 1].text;
 }
 var ln = i;
 break;
   }
}
 if(ln < abox.options.length)  {
  abox.options.length -= 1;
  BumpUp(abox);
   }
}
function Moveup(dbox) {
 for(var i = 0; i < dbox.options.length; i++) {
 if (dbox.options[i].selected && dbox.options[i] != "" && dbox.options[i] != dbox.options[0]) {
 var tmpval = dbox.options[i].value;
 var tmpval2 = dbox.options[i].text;
  dbox.options[i].value = dbox.options[i - 1].value;
  dbox.options[i].text = dbox.options[i - 1].text
  dbox.options[i-1].value = tmpval;
  dbox.options[i-1].text = tmpval2;
      }
   }
}
function Movedown(ebox) {
 for(var i = 0; i < ebox.options.length; i++) {
 if (ebox.options[i].selected && ebox.options[i] != "" && ebox.options[i+1] != ebox.options[ebox.options.length]) {
 var tmpval = ebox.options[i].value;
 var tmpval2 = ebox.options[i].text;
  ebox.options[i].value = ebox.options[i+1].value;
  ebox.options[i].text = ebox.options[i+1].text
  ebox.options[i+1].value = tmpval;
  ebox.options[i+1].text = tmpval2;
      }
   }
}
//-->
</script>

</HEAD>

<BODY>

<form ACTION="" METHOD="POST">
<table>
<tr>
 <td colspan=2>
  <input type="text" name="list1" size=21 value=""> <input type="button" value="추가" onclick="move(this.form.list1,this.form.list2)" name="B1" style="width:60">

 </td>
</tr>
<tr>
 <td>
  <select multiple size=7 name="list2" style="width:160">
  <option value="one">하나</option>
  <option value="two">둘</option>
  <option value="three">셋</option>
  <option value="four">넷</option>
  <option value="five">다섯</option>
  <option value="six">여섯</option>
  </select>
 </td>
 <td>
  <input type="button" value="삭제" onclick="remove(this.form.list2)" name="B2" style="width:60">

  <input type="button" value="위로" onclick="Moveup(this.form.list2)" name="B3" style="width:60">

  <input type="button" value="아래로" onclick="Movedown(this.form.list2)" name="B4" style="width:60">
 </td>
</tr>
</table>
</form>

</BODY>
</HTML>

selectBox-ex.html

Posted by 말없제이
,

function isHangul(sVal)
{
  var sBit = '';

  for(i=0;i<sVal.length;i++)
  {
    sBit = sVal.charAt(i);
    if(escape( sBit ).length <= 4)
    {
   alert("한글만 입력하십시오.");
      return false;
    }
  }
  return true;
}

 

Posted by 말없제이
,

// 문자 Count
function cal_byte()
{
    var aquery = document.getElementById("<%=txtMessage.ClientID%>").value;
 var tmpStr;
 var temp=0;
 var onechar;
 var tcount;
 tcount = 0;

 tmpStr = new String(aquery);
 temp = tmpStr.length;

 for (k = 0; k < temp; k++)
 {
  onechar = tmpStr.charAt(k);
  
  if (escape(onechar) =='%0D')
  {
  }
  else if(escape(onechar).length > 4)
  {
      tcount += 2;
  }
  else
  {
      tcount++;
        }
 }
   
    document.getElementById("<%=txtByte.ClientID %>").innerHTML = tcount;
   
    if(tcount > 80)
    {
  reserve = tcount - 78;
  alert("문자는 80바이트를 넘을수 없습니다." );
  cutText(); 
 } 
}

// OverFlow 문자 자르기
function cutText()
{
 nets_check(document.getElementById("<%=txtMessage.ClientID%>").value);
}

// OverFlow 문자 자르기
function nets_check(aquery)
{
 var tmpStr;
 var temp=0;
 var onechar;
 var tcount;
 tcount = 0;

 tmpStr = new String(aquery);
 temp = tmpStr.length;

 for(k = 0; k < temp; k++)
 {
  onechar = tmpStr.charAt(k);

  if(escape(onechar).length > 4)
  {
   tcount += 2;
  }
  else
  {
   tcount++;
  }

  if(tcount > 80)
  {
   tmpStr = tmpStr.substring(0, k);
   break;
  }
 }
  
 document.getElementById("<%=txtMessage.ClientID%>").value = tmpStr;
 cal_byte();
}

Posted by 말없제이
,

//원하는 케릭터형 모드 Replace
String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/gi, "");
}

String.prototype.replaceAll = function(str1, str2)
{
    var temp_str = "";
   
    if(this.trim() != "" && str1 != str2)
    {
        temp_str = this.trim();
       
        while(temp_str.indexOf(str1) > -1)
        {
            temp_str = temp_str.replace(str1, str2);
        }
    }
   
    return temp_str;
}

Posted by 말없제이
,

<script type="text/javascript">

    function ieExecWB(intOLEcmd, intOLEparam) {
        // 웹 브라우저 컨트롤 생성
        var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';

        // 웹 페이지에 객체 삽입
        document.body.insertAdjacentHTML('beforeEnd', WebBrowser);

        // if intOLEparam이 정의되어 있지 않으면 디폴트 값 설정
        if ((!intOLEparam) || (intOLEparam < -1) || (intOLEparam > 1))
            intOLEparam = 1;

        // ExexWB 메쏘드 실행
        WebBrowser1.ExecWB(intOLEcmd, intOLEparam);

        // 객체 해제
        WebBrowser1.outerHTML = "";
        window.close();
    }

    </script>
</head>
<body onload="window.print();">

Posted by 말없제이
,


[JavaScript] 날짜 가감 함수 addDate()  HTML/JavaScript  2008/10/10 16:24

 http://blog.naver.com/dalbong97/130036098383


 
VBScript 의 DateAdd 함수와 유사한 기능을 하도록 만든 JavaScript 용 함수

 

/* ----------------------------------------------------------------------------
 * 특정 날짜에 대해 지정한 값만큼 가감(+-)한 날짜를 반환

 *

 * 입력 파라미터 -----
 * pInterval : "yyyy" 는 연도 가감, "m" 은 월 가감, "d" 는 일 가감
 * pAddVal  : 가감 하고자 하는 값 (정수형)
 * pYyyymmdd : 가감의 기준이 되는 날짜
 * pDelimiter : pYyyymmdd 값에 사용된 구분자를 설정 (없으면 "" 입력)

 *

 * 반환값 ----

 * yyyymmdd 또는 함수 입력시 지정된 구분자를 가지는 yyyy?mm?dd 값
 *

 * 사용예 ---

 * 2008-01-01 에 3 일 더하기 ==> addDate("d", 3, "2008-08-01", "-");

 * 20080301 에 8 개월 더하기 ==> addDate("m", 8, "20080301", "");
 --------------------------------------------------------------------------- */
 


function addDate(pInterval, pAddVal, pYyyymmdd, pDelimiter)
{
 var yyyy;
 var mm;
 var dd;
 var cDate;
 var oDate;
 var cYear, cMonth, cDay;
 
 if (pDelimiter != "") {
  pYyyymmdd = pYyyymmdd.replace(eval("/\\" + pDelimiter + "/g"), "");
 }
 

 yyyy = pYyyymmdd.substr(0, 4);
 mm  = pYyyymmdd.substr(4, 2);
 dd  = pYyyymmdd.substr(6, 2);
 
 if (pInterval == "yyyy") {
  yyyy = (yyyy * 1) + (pAddVal * 1);
 } else if (pInterval == "m") {
  mm  = (mm * 1) + (pAddVal * 1);
 } else if (pInterval == "d") {
  dd  = (dd * 1) + (pAddVal * 1);
 }
 

 cDate = new Date(yyyy, mm - 1, dd) // 12월, 31일을 초과하는 입력값에 대해 자동으로 계산된 날짜가 만들어짐.
 cYear = cDate.getFullYear();
 cMonth = cDate.getMonth() + 1;
 cDay = cDate.getDate();
 
 cMonth = cMonth < 10 ? "0" + cMonth : cMonth;
 cDay = cDay < 10 ? "0" + cDay : cDay;

 

 if (pDelimiter != "") {
  return cYear + pDelimiter + cMonth + pDelimiter + cDay;
 } else {
  return cYear + cMonth + cDay;
 }
 
}
[출처] [JavaScript] 날짜 가감 함수 addDate()|작성자 후리랜서

Posted by 말없제이
,

참조 : http://kldp.org/node/90444


function getNavigatorInfoStr()
{
    var name = navigator.appName, ver = navigator.appVersion,
        ver_int = parseInt(navigator.appVersion), ua = navigator.userAgent, infostr;
    if(name == "Microsoft Internet Explorer")
    {
        if(ver.indexOf("MSIE 3.0") != -1) return "Internet Explorer 3.0x";
        if(ver_int != 4) return "Internet Explorer " + ver.substring(0, ver.indexOf(" "));
 
        var real_ver = parseInt(ua.substring(ua.indexOf("MSIE ") + 5));
        if(real_ver &gt;= 7) infostr = "Windows Internet Explorer ";
        else infostr = "Microsoft Internet Explorer ";
 
        if(ua.indexOf("MSIE 5.5") != -1) return infostr + "5.5";
        else return infostr + real_ver + ".x";
 
        return "Internet Explorer";
    }
    else if(name == "Netscape")
    {
        if(parseInt(ua.substring(8, 8)) &lt;= 4)
          return "Netscape " + ver.substring(0, ver.indexOf(" "));
        else if(ua.lastIndexOf(" ") &lt; ua.lastIndexOf("/"))
          return ua.substring(ua.lastIndexOf(" "));
        else return "Netscape";
    }
    else return name;
}
 
function getOSInfoStr()
{
    var ua = navigator.userAgent;
 
    if(ua.indexOf("NT 6.1") != -1) return "Windows 7";
    else if(ua.indexOf("NT 6.0") != -1) return "Windows Vista/Server 2008";
    else if(ua.indexOf("NT 5.2") != -1) return "Windows Server 2003";
    else if(ua.indexOf("NT 5.1") != -1) return "Windows XP";
    else if(ua.indexOf("NT 5.0") != -1) return "Windows 2000";
    else if(ua.indexOf("NT") != -1) return "Windows NT";
    else if(ua.indexOf("9x 4.90") != -1) return "Windows Me";
    else if(ua.indexOf("98") != -1) return "Windows 98";
    else if(ua.indexOf("95") != -1) return "Windows 95";
    else if(ua.indexOf("Win16") != -1) return "Windows 3.x";
    else if(ua.indexOf("Windows") != -1) return "Windows";
    else if(ua.indexOf("Linux") != -1) return "Linux";
    else if(ua.indexOf("Macintosh") != -1) return "Macintosh";
    else return "";
}

그냥 재미로 짜봤습니다. 유용할 거라고 믿어요.
테스트 환경:
Windows Vista, Internet Explorer 7.0
Windows Server 2008, Internet Explorer 7.0
Windows Me, Internet Explorer 5.5
Windows Vista, Firefox 3.0b2
Windows Vista, Firefox 2.0.0.10
Windows Vista, Netscape Navigator 9.0
Windows Vista, Mozilla SeaMonkey 1.1.6
Ubuntu 7.04, Firefox 2.0.0.10
물론 테스트 환경에서 잘못 나온 건 없었습니다.

참조 : http://kldp.org/node/90444

Posted by 말없제이
,