부모 자식 사이의 자바스크립트 호출
iframe 내의 자바스크립트를 호출하는 방법
부모 자식 간의 자바스크립트 호출
▶ 키포인트
부모 -> 자식 호출은 contentWindow
자식 -> 부모 호출은 parent
▶ 부모
<html>
<head>
<script type="text/javascript">
function exam_func_parent() {
alert('부모 자바스크립트 함수');
}
function call_child_func() {
var iObj = document.getElementById('frame1').contentWindow;
iObj.exam_func_child();
}
</script>
<head>
<body>
<input type="button" name="자식함수호출" onclick="call_child_func();" />
<iframe src="" name="frame1" id="frame1" width="100%" height="100%"></iframe>
</body>
</html>
▶ 자식
<html>
<head>
<script type="text/javascript">
function exam_func_child() {
alert('자식 자바스크립트 함수');
}
function call_parent_func() {
parent.exam_func_parent();
}
</script>
</head>
<body>
<input type="button" name="부모함수호출" onclick="call_parent_func();" />
</body>
</html>
◎ iframe -> iframe 두단계라면
자식.자식.함수호출
document.getElementById('frame1').contentWindow.document.getElementById('frame1').contentWindow.exam_func_child();
부모.부모.함수호출
parent.parent.exam_func_parent();