조각이론

팝업에서 부모창 제어하기 본문

JavaScript/JQuery

팝업에서 부모창 제어하기

조각이론 2018. 12. 2. 22:09


//부모창의 필드값 갖고 오기



1. 일반적인 방법


var parentValue = opener.document.getElementById("parentId").value;


 


2. jQuery를 이용한 방법


$("#parentId", opener.document).val();


 


3. find를 이용한 방법


$(opener.document).find("#parentId").val();



 


 


//동적으로 생성한 폼을 부모창에 붙이기



1. jQuery를 이용한 방법


$(opener.document).find("#parentId").append(html);


 


 


//팝업창에서 부모창 함수 호출


1-1. 일반적인 방법


opener.location.href = "javascript:부모스크립트 함수명();";


opener.location.href = "http://www.aaa.com";


 


1-2. 일반적인 방법


window.opener.fnCall();


 


2. jQuery를 이용한 방법


$(opener.location).attr("href", "javascript:부모스크립트 함수명();");


 


 


//팝업창에서 부모창으로 값 넘기기


1-1. 일반적인 방법


window.opener.document.getElementById("parentId").value = "부모창으로 전달할 값";


 


1-2. 일반적인 방법


window.opener.폼네임.parentInputName.value = value;


 


2. jQuery를 이용한 방법


$("#parentEleId", parent.opener.document).val(부모창으로 전달할 값);


$("#parentEleId", parent.opener.document).text(부모창으로 전달할 값);


 


3. find를 이용한 방법


$(opener.document).find("#parentId").val(부모창으로 전달할 값);



 


 


//부모창의 CSS 변경



1. jQuery를 이용한 방법


$("#parentId", opener.document).css("display", "none");


opener.document.bgColor = "yellow"; //부모창 배경색 설정


 


 


//팝업창 닫기


window.self.close();


 


 


//페이지 새로고침


​// 팝업창 자신 페이지 새로고침


document.location.reload();




// 부모창 페이지 새로고침


opener.location.reload();






//팝업창에서 부모창 새로고침(새로고침 의사 표현을 묻는 창이 뜸)


window.opener.parent.location.reload();


window.opener.document.location.reload();





//URL을 부모창이 있으면 부모창으로 보내고, 부모창이 닫히거나 존재하지 않을 경우 새창으로 열기


function fnGoOpener(url) {


   if(opener.closed) {   //부모창이 닫혔는지 여부 확인


      // 부모창이 닫혔으니 새창으로 열기


      window.open(url, "openWin");


   } else {


      opener.location.href = url;


      opener.focus();


   }


}