[英]Display a part of web page using iframe
I have a dynamic table on a web page and i am calling that page on another application. 我在网页上有一个动态表,并且正在另一个应用程序上调用该页面。 i am trying to display that table alone and not the whole page. 我试图单独显示该表,而不是整个页面。 So i wrote a code based on some other answers on stack exchange. 所以我根据堆栈交换中的其他一些答案编写了代码。 But still it shows the whole page. 但是仍然显示整个页面。 If the table has just 2 rows, then it shows the table with 2 rows and the whole empty page. 如果表只有2行,那么它将显示具有2行的表和整个空白页。 Not able to figure out whats wrong. 无法找出问题所在。 Is there any other way ? 还有其他办法吗?
<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>
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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.