2012-01-16 2 views
1

한 페이지를iframe 콘텐츠에 다른 iframe으로 어떻게 액세스합니까?

<div id="editForm_container"> 
<form id="imageForm" name="imageForm" enctype="multipart/form-data" target="hiddenFrame" method="post" action="test.php">     

    <label><strong>File Name</strong></label> 
    <input type="file" name="fileupload" id="fileupload" /><br /> 
    <input type="submit" name="submit_image" id="submit_image" /> 

</form> 
<iframe id="hiddenFrame" name="hiddenFrame"></iframe> 

을하고 난 에 다른 페이지에있는 다른 iframe이이 페이지를로드하고 나는이 빈을 반환

$("#imageFrame").load(function(){ 

this.imageFramecontent = $("#imageFrame").contents(); 
this.imageFramefields.fileField = this.imageFramecontent.find(":input[ name = 'fileupload' ]"); 
this.imageFrameform = this.imageFramecontent.find("form#imageForm"); 
this.hiddenFrame = this.imageFramecontent.find("iframe#hiddenFrame"); 

this.imageFramefields.fileField.change(function(){ 

    self.imageFrameform.submit(); 
    self.hiddenFrame.load(function(){ 

     alert(self.hiddenFrame.contents().html()); 
    });      
}); 

파일 내 JS에서 쓴 경보. #hidden 프레임 내용을 얻으려면 어떻게해야합니까?

+0

은 같은 도메인에로드 된 모든 iframe입니까? 자바 스크립트 콘솔에서 어떤 오류가 발생 했습니까? – fcalderan

+0

같은 도메인에 있습니다. 콘솔 반환 오류 없음 – user1066679

+0

@ FabrizioCalderan 해결책이있는 경우이 문제에 도움주세요 ... 제발 – user1066679

답변

2

가까운 사이. .contents() 메서드는 DOM 요소 집합을 반환하므로 HTML을 반환 할 요소를 지정해야합니다. 그래서 당신은이 같은 라인 필요할 것 :

hiddenFrame.contents().find('html').html(); 

내가 꽤 위에서 제공되는 코드를 실행하는 샘플을 얻을 수 없었다, 그러나 나는 다음과 같은 비틀기 작업 얻을 관리 :

$("#imageFrame").load(function(){ 

    imageFramecontent = $("#imageFrame").contents(); 
    imageFrameupload = imageFramecontent.find(":input[ name = 'fileupload' ]"); 
    imageFrameform = imageFramecontent.find("form#imageForm"); 
    hiddenFrame = imageFramecontent.find("iframe#hiddenFrame"); 

    imageFrameupload.change(function(){ 

     hiddenFrame.load(function(){ 

      alert(hiddenFrame.contents().find('html').html()); 

     }); 
     imageFrameform.submit(); 

    }); 
}); 
+0

당신은 천재 Goran이며 도움 주셔서 감사합니다 귀하의 솔루션은 많은 issues.Thank 당신을 해결했습니다 – user1066679

관련 문제