0

我在网页上有一个动态表格,我正在另一个应用程序上调用该页面。我试图单独显示该表而不是整个页面。所以我根据堆栈交换的其他一些答案编写了一个代码。但它仍然显示整个页面。如果表格只有 2 行,则显示有 2 行的表格和整个空白页。无法弄清楚什么是错的。还有其他方法吗?

<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>
4

1 回答 1

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
    }

}
于 2013-10-29T23:42:17.110 回答