예제소스 - http://bboong100.cafe24.com/0911/test02.html

 

test02.html  (부모창)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
<script type="text/javascript">
function popup()
{
    var flag;
    //http://naver.com
    var url = "popup1.html";
    var popupname = "popupwin";

    flag = "left=200, ";
    flag += "top=200, ";
    flag += "width=400, ";
    flag += "height=250";
    window.open(url, popupname, flag);
}

function popuptest1(name, code)
{
    var testtable = document.getElementById("popuptest");
    var tr = document.createElement("tr");
    tr.setAttribute("height", "30");
    if (name == "" || code == "") {
        alert('문자 입력하시오');
        return;
    }

    var td1 = document.createElement("td");
    td1.setAttribute("width", "100");

    var td2 = document.createElement("td");
    td2.setAttribute("width", "200");

    tr.appendChild(td1);
    tr.appendChild(td2);

    td1.innerText = name;
    td2.innerText = code;

    if (testtable.firstChild.lastChild.childNodes.length == 1)
        testtable.firstChild.removeChild(testtable.firstChild.lastChild);

    testtable.firstChild.appendChild(tr);
}
 </script>
 </HEAD>
 <BODY>
 
    팝업테스트  <input type="button" value="popup" onclick="popup()"> <p><p>
    <table id="popuptest" border="2">
        <tr>
            <th width="100">name</th>
            <th width="100">code</th>
        </tr>
    </table>
 </BODY>
</HTML>

 


test02_1.html   (자식창_팝업창)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
<script type="text/javascript">
        function add2()
        {
            var name = document.ex.name.value;
            var code = document.ex.code.value;
            opener.popuptest1(name, code);
            self.close()
        }

        function reset()
        {
            document.all.name.value="";
            document.all.code.value="";
        }
 </script>
 </HEAD>
 <BODY>
 
<form name='ex'>
 Name : <input type="text" size="10" name="name" id="name" ><br>
 Code : <input type="text" size="10" name="code" id="code" ><br>

 <input type="button" value="추가" onclick="add2()">
 <input type="button" value="초기화" onClick="reset();">

</form>
 </BODY>
</HTML>

'개발개발 > 자바스크립트' 카테고리의 다른 글

계산기 진행상황 (0915)  (1) 2012.09.15
문서객체  (0) 2012.09.11
0906 자바스크립트 계산기  (0) 2012.09.06
계산기 문제점  (0) 2012.09.06
0905 자바스크립트 계산기  (0) 2012.09.05
Posted by 공돌공돌
,