如何让网页Iframe自适应高度和宽度

以前用过的,不过这次想用,整了半天才整出来,费劲啊,还是写下来吧.
首先,你需要在页面里写上iframe,然后定义ID, 像这样:

1
<IFRAME id=”框架ID名” name=”left” frameBorder=0 scrolling=no src=”XXX.asp” width=”100%”></IFRAME>

然后在XXX.asp页面的任何一个位置,最好是尾部,写上如下代码:

1
2
3
4
<script>
parent.document.all(“框架ID 名”).style.height=document.body.scrollHeight;
parent.document.all(“框架 ID名”).style.width=document.body.scrollWidth;
</script>

好了,简单吧,就这么几句.你试试,我在IE6,IE7下测试正常.

This entry was posted in javascript and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>