본문 바로가기

프로그래밍언어/jquery

jquery 부모창에 있는 iframe 접근 및 제어 방법

팝업창에서 자신을 호출한 부모 창에 접근
$("접근하고자하는요소" , opener.document)


 iframe 안에서 자신을 가지고 있는 부모창에 접근
$("접근하고자하는요소" , parent.document)

부모 창에 있는 iframe 접근

// 부모창의 iframe이 새로고침
$("#ifrm",parent.document).get(0).contentDocument.location.reload();


// 부모창의 iframe이 모두 load 된 후 특정 행동을 하게 하기 위한 코드
$("#ifrm",parent.document).load(이동할 주소, function(){
   // 실행할 내용
  // 팝업에서 openr.document로 해서 실행했을때 팝업창이 열려있을때 새로고침을 하면, 
  // 팝업에 있는 이 함수를 타고 iframe의 로딩 작업을 함.
  // 이동할 주소에서 해로고침을해서 값을 새로설정하는 부분이 있다면
  // if문으로 타야할지 말아야할지 구분해주는 코드 필요. 
});


// 부모창에 있는 iframe안의 요소 접근 및 제어
$("#ifrm", parent.document).contents().find("#txtAlert").val("요소제어");


// 부모창에 있는 iframe안의 함수 실행
$("#ifrm", parent.document).get(0).contentWindow.openpop();


// 부모창에 있는 iframe안의 변수 실행
$("#ifrm", parent.document).get(0).contentWindow.varName();


// iframe에서 부모창에 있는 iframe 제어하기
$('제어할 아이디', parent.frames["부모창 제어할 frame의 name값"].document).html("여기도 제어한다.");

'프로그래밍언어 > jquery' 카테고리의 다른 글

jquery 라디오버튼 체크 prop  (0) 2017.10.11
jquery iframe 부모 접근, 자식 접근  (0) 2017.09.11