JavaScript

210924_window.open/close,버튼,opener

요옫 2021. 9. 24. 17:40

(dataOpen.html)

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

<script type="text/javascript">

  function dataOpen(){ 

  window.open('ex8_dataSend.html','w','width=300,height=200');  /*코드 중에서 'w'는 그냥 아무 이름 붙인 거 */

  }

 

</script>

</head>

<body>

<form action="" name="frm">

  <table>

    <tr>

      <th width="100">이름</th>

      <td width="200">

<!-- 입력 안 할거기에 readonly="readonly" -->

        <input type="text" name="name" readonly="readonly"> 

      </td>

    </tr>

    

    <tr>

      <th width="100">주소</th>

      <td width="200">

        <input type="text" name="addr" readonly="readonly">

      </td>

    </tr>

 

    <tr>

      <th width="100">연락처</th>

      <td width="200">

        <input type="text" name="hp" readonly="readonly">

      </td>

    </tr> 

    

    <tr align="center">

      <td colspan="2"><input type="button" value="데이터 입력" onclick="dataOpen()"></td>

    </tr> 

  

  </table>

</form>

</body>

</html>

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

(dataSend.html)

 

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

<script type="text/javascript">

function dataSend(){

/* opener는 현재 열려있는 곳을 의미..여기선 dataopen */

opener.frm.name.value=frm.name.value;

opener.frm.addr.value=frm.addr.value;

opener.frm.hp.value=frm.hp.value;

 

//열려있는 곳이 open.document

window.close();

}

 

</script>

</head>

<body>

<form action="" name="frm" onsubmit="return false">

  <table>

    <tr>

      <th width="100">이름</th>

      <td width="200">

<!-- 데이터 입력이기에 readonly="readonly 제거해야 함 -->

<!-- required="required : 반드시 데이터를 입력해줘야 함 -->

        <input type="text" name="name" required="required"> 

      </td>

    </tr>

    

    <tr>

      <th width="100">주소</th>

      <td width="200">

        <input type="text" name="addr">

      </td>

    </tr>

 

    <tr>

      <th width="100">연락처</th>

      <td width="200">

        <input type="text" name="hp">

      </td>

    </tr> 

    

    <tr align="center">

      <td colspan="2"><input type="button" value="데이터 전송" onclick="dataSend()"></td>

    </tr> 

  

  </table>

</form>

</body>

</html>

 

기본화면

 

 

데이터 입력

 

 

전송 버튼 누르면 기본화면에 데이터 출력