재우니의 블로그

 

jQuery 로 iframe 의 내부 값 가져오기

 

부모페이지

 

<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
   <script type='text/javascript'>
 function init() {
  var getval = $('#my_iframe').contents().find('#someID').html();
  alert(getval);
 }
</script>
 </head>
 <body onload="init()">
 

<IFRAME id="my_iframe" NAME='my_iframe' SRC='test.html'></IFRAME>

<a onclick="init()">test</a>

 </body>
</html>

 

 

iframe 내부 페이지

 

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
 </head>
 <body>
  <div id="someID">Hello world!</div>
 </body>
</html>