---
title: "Iframe自适应高度"
author: "lunch"
date: "2007-12-10T11:42:30Z"
tags: []
categories: ["非技术"]
slug: "iframe"
draft: false
lastmod: "2007-12-10T11:42:30Z"
id: 147208
url: "https://lunch.iteye.com/blog/147208"
---

在做页面的时候经常会用到iframe,同样iframe的高度问题一直比较烦人。现在给术一个让iframe根据所包含页面的高度设置自己的高度。
　　
　　调用本地文件，写法如下：
　　
```
<iframe id="test" src="test1.htm" 
　　　　　　　　　　onload="this.height=test.document.body.scrollHeight"
　　　　　　　　　　frameborder="0"></iframe>
```

调用http页面，必须加上document.all.

```

document.all.test.height=document.all.test.document.body.scrollHeight

```