您的位置:首页 > Web前端 > CSS

IFRAME自动适应的问题

2007-08-27 08:27 274 查看
<script type="text/javascript"><!--
google_ad_client = "pub-4490194096475053";
/* 内容页,300x250,第一屏 */
google_ad_slot = "3685991503";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>iframe src="show.htm" id="show" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" width="100%" onload="this.height=0;var fdh=(this.Document?this.Document.body.scrollHeight:this.contentDocument.body.offsetHeight);this.height=(fdh>7?fdh:7)"></iframe>
注:onload字段中的数值“7”为Iframe最低高度值,可自定义!
另外这个同时支持IE&Firefox:)

PS:如果内页的CSS设置了BODY的MARGIN属性,IFRAME自适应的高度不会把margin-top和margin-bottom的值加到里面,所以最后这地方this.height=(fdh>450?fdh:400)得改成
this.height=(fdh>450?fdh+margin-top的高度+margin-bottom的高度:400)
比如说
this.height=(fdh>450?fdh+20+15:400) //尚未测试  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iframe 测试 css