프로그램언어/자바스크립트
iframe 안에 정의된 자바스크립트 변수를 iframe 밖에서 jQuery 로 접근하는 방법, contentWindow
발가락
2013. 9. 27. 07:41
728x90
A.html 안에 아래와 같이 iframe 이 존재하고,
<iframe name="iframe1" id="iframe1"></iframe>
B.html 안에는 아래와 같이 자바스크립트 변수가 존재할때..
<script>
...
var var1 = '어쩌구저쩌구';
...
</script>
A.html 안에서 jQuery 를 사용하여 B.html 안에 있는 변수를 가져다 쓰려면 어떻게 해야 할까요..?
이런 경우.. contentWindow 라는 넘을 사용합니다.
A.html 안에서 $('#iframe1').get(0).contentWindow.var1;