我想要iframe足够大,不需要滚动条,并且如果需要的话,需要浏览器呈现滚动条。如何根据其内容调整iframe的大小?
以前有帖子,我知道...但是..很多不是挺我的问题。
主页面和iframe在同一个域中。
我想要iframe足够大,不需要滚动条,并且如果需要的话,需要浏览器呈现滚动条。如何根据其内容调整iframe的大小?
以前有帖子,我知道...但是..很多不是挺我的问题。
主页面和iframe在同一个域中。
<html>
<script type="text/javascript">
function autoIframe(frameId){
try{
frame = document.getElementById(frameId);
innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
objToResize = (frame.style) ? frame.style : frame;
objToResize.height = innerDoc.body.scrollHeight + 10;
}
catch(err){
window.status = err.message;
}
}
</script>
<iframe id="tree" name="tree" src="tree.htm" onload="if (window.parent && window.parent.autoIframe) {window.parent.autoIframe('tree');}"></iframe>
这是一个脚本我保存在我的temlates,它不是我的虽然!但我不记得谁是作者..
做在谷歌搜索返回:
<script language="JavaScript">
function calcHeight()
{
//find the height of the internal page
var the_height=
document.getElementById('the_iframe').contentWindow.
document.body.scrollHeight;
//change the height of the iframe
document.getElementById('the_iframe').height=
the_height;
}
<iframe name="the_iframe" onLoad="calcHeight();" scrolling="no" width="730" id="the_iframe" src="you_page.html" frameborder="0" allowtransparency="true"></iframe>
您可以访问iFrame的内容,如果他们是在同一个域:
这样做,你应该能够从内容获得某种高度/宽度/偏移值,并适当调整iframe的大小。
当然,如果他们确实在同一个域上,也许AJAX调用DIV会更有意义。