β index.jsp >>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:url value="/resources/js/popup/index.js" var="js1"/>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>νμ
μ°½ μ΄κΈ°</title>
</head>
<body>
<input id="addr" type="text" />
<button id="btn1">νμ
μ΄κΈ°</button>
<!-- c:urlμμ μ€μ ν var κ°μ μ£Όλ©΄λ¨ -->
<script src="${js1}"></script>
</body>
</html>
β popup.jsp >>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>λ²νΌμ λλ₯΄λ©΄ μμ°½μμ μ΄λ¦¬λ νμ
μ°½μ
λλ€</title>
</head>
<body>
μ μ°½μμ μ΄λ¦΄ λ΄μ©μ
λλ€ ... <br>
<br>
μ΄ νμ
μ°½μ μ° λΆλͺ¨μ°½μ openerλΌλ κ°μ²΄λ‘ μ κ·Όν μ μλ€. <br>
<script src="<%=request.getContextPath() %>/resources/js/popup/popup.js"></script>
</body>
</html>
β index.js >>
const btn1 = document.getElementById('btn1');
btn1.addEventListener('click',(e)=> {
window.open('./popup.jsp','_blank',
'width=500, height=500, top=100, left=100'); // μ μ°½μ μ΄μ΄μ£Όλ μλ°μ€ν¬λ¦½νΈ ν¨μ
});
β popup.js >>
//opener : μ΄ μ°½μ μ° λΆλͺ¨ κ°μ²΄ window
console.log(opener);
console.log(opener.document.getElementById('addr'));
opener.document.getElementById('addr').value='apple';
opener.document.body.style.backgroundColor='green';
πΊ νλ©΄ μΆλ ₯ >>
νμ
μ΄κΈ° λ²νΌμ λλ μ λ >>
νμ
>>
index.jsp νλ©΄ >>