<html>
<head>
<meta charset="UTF-9">
<title>BOM PARENT</title>
</head>
<body>
<button>창열기</button>
<button>창닫기</button>
<br/>
자식창으로 보낼 데이터 :
<input type="text" id="toChild"/>
<input type="button" value="보내기" onclick="sendVal()"/>
<br/>
자식창에서 보낸 데이터 :
<input type="text" id="fromChild"/>
</body>
<script>
var win;
var btn = document.getElementsByTagName('button');
btn[0].addEventListener('click',function(){
win = window.open('./09_child.html','','width=430,height=200');
})
btn[1].addEventListener('click',function(){
win.close();
})
function sendVal(){
var val = document.getElementById('toChild').value;
win.document.getElementById('fromParent').value = val;
console.log(val);
}
function plus(a,b){
console.log('부모 함수 plus 실행 : ',a+b);
}
</script>
</html>
<html>
<head>
<meta charset="UTF-9">
<title>BOM CHILD</title>
</head>
<body>
<h3>자식창</h3>
부모로부터 받아온 값:
<input type="text" id="fromParent"/>
<br/>
부모창으로 보낼 값 :
<input type="text" id="toParent"/>
<input type="button" value="보내기" onclick="sendVal()"/>
</body>
<script>
function sendVal(){
console.log('부모에게 데이터 보내기');
var val = document.getElementById('toParent').value;
opener.document.getElementById('fromChild').value = val;
opener.plus(10,20);
}
</script>
</html>