2013-10-29 5 views
0

웹 페이지에 동적 테이블이 있으며 다른 페이지에서 해당 페이지를 호출하고 있습니다. 나는 전체 페이지가 아닌 그 테이블 만 표시하려고합니다. 그래서 스택 교환에 대한 다른 답변을 기반으로 코드를 작성했습니다. 하지만 여전히 전체 페이지를 보여줍니다. 표에 2 행만 있으면 2 행의 표와 전체 빈 페이지가 표시됩니다. 뭐가 잘못 됐는지 알아낼 수 없어요. 다른 방법이 있습니까? 두 페이지가 같은 서버에있는 경우iframe을 사용하여 웹 페이지의 일부를 표시하십시오.

<script language="javascript" type="text/javascript"> 
function resizeIframe(obj) { 
obj.style.height = obj.contentWindow.document.getElementById("dvMain").offsetHeight + 'px'; 
// alert(obj.style.height); 
} 
</script> 


<iframe src="www.google.com" width="100%" marginwidth="0" marginheight="0" frameBorder="0" id="iframe" onload='javascript:resizeIframe(this);'> 
</iframe> 
+0

당신은 텍스트 응답을로드 XMLHttpRequest를 사용할 수와 는 div 요소의 innerHTML로에 <테이블에서 비트를 사용합니다. 동일한 출처가 아닌 경우 contentWindow 속성을 읽을 수 없습니다. – kennebec

+0

@kennebec : 답변 해 주셔서 감사합니다. 코드 개요를 보여 주시겠습니까? 페이지는 동일한 서버에 있습니다. – Ann

답변

0
function tableFromUrl(url, target, before){ 
    url is the file path, 
    target is an element to append the table to, if there are two arguments. 
    Or, if a third argument is true, insert the table before the target element. 
    try{ 
     var O= new XMLHttpRequest(), txt, 
     div= document.createElement('div'); 
     O.open('GET', url, true); 
     O.onreadystatechange= function(){ 
      if(O.readyState== 4 && O.status== 200){ 
       txt= O.responseText; 
       div.innerHTML=txt.substring(t.search(/<table/), t.search(/<\/table>/))+'</table>'; 
       if(before=== true) target.parentNode.insertBefore(div, target); 
       else target.appendChild(div); 
      } 
     } 
     O.send(null); 
    } 
    catch(er){ 
     //error handler 
    } 

} 
+0

응답 해 주셔서 다시 한번 감사드립니다. 나는 마침내 약간의 수정 후에 자바 스크립트로 원하는 결과를 얻었다. – Ann

관련 문제