> For the complete documentation index, see [llms.txt](https://wiki.co2oc.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.co2oc.com/qian-duan/jian-rong-xing-+hack/01iframe-zi-shi-ying-gao-du.md).

# 01 iframe 自适应高度

## 1.父页面和 iframe 同源

## 2.父页面和 iframe 不同源

> [iframe-resizer 开源代码](https://github.com/davidjbradshaw/iframe-resizer)\
> 注：v3 才支持 IE8

使用 `iframeResizer.min.js` 和 `iframeResizer.contentWindow.min.js` 来处理。 `iframeResizer.min.js` 放在父页面中，`iframeResizer.contentWindow.min.js` 放在 iframe 中。

### 父页面

> 需要注意的是width必须是百分比，scrolling设置为no（为了兼容性）

```markup
  <body>
    <iframe
      id="formB"
      frameborder="0"
      scrolling="no"
      src="http://example.com/example/index.php"
      width="100%"
      height="100%"
    ></iframe>

    <script src="iframeResizer.min.js"></script>

    <script>
      $('#formB').iFrameResize([{ log: true }]);
    </script>
  </body>
```

### iframe

```markup
    <body>

        其它内容

        <script src="iframeResizer.contentWindow.min.js"></script>
    </body>
```
