2011-03-08 3 views
0

대상이있는 양식을 iFrame에 제출합니다. 이제 iFrame의 innerHTML을 얻으려고하면 null이됩니다. 여기 내 코드는 다음과 같습니다.iFrame의 업데이트 된 값 가져 오기

조치는 iFrame에 설정할 id 값을 반환합니다. 이제 iFrame의 innerHTML을 얻으려고 할 때 null이 표시됩니다. UI에서 iFrame의 id 값을 볼 수 있습니다.

JS 코드 :

alert(document.getElementById("upload_target").innerHTML); 

가 어떻게 iframe이에서 id 값을받을 수 있나요?

당신은 iframe이 내용을 액세서하는 contentWindow 속성을 사용한다

답변

0

:

<html> 
<head runat="server"> 
    <title>Upload Result</title> 
</head> 
<body> 
    <script type="text/javascript"> 
     window.onload = function() { 
      var fn = parent['uploadSuccess']; 
      if (fn) { 
       fn(<fileId>); 
      }    
     }; 
    </script> 
</body> 
</html> 

그리고 parrent 창에서 :

document.getElementById('upload_target').contentWindow.document.documentElement.innerHTML 
0

당신은 parrent 창에서 콜백 함수를 호출하는 HTML 페이지를 반환 할 수 있습니다 :

window['uploadSuccess'] = function(fileId) { 
    // do something with the fileId 
}