# iframe 高度自適應
>[success]在這里介紹兩種方式來實現,在這時將使用jquery快速實現
>
## 方法一:在iframe頁面中加入統一js代碼
~~~
//注意:下面的代碼是放在和iframe同一個頁面中調用
$("#iframeId").load(function () {
var mainheight = $(this).contents().find("body").height() + 30;
$(this).height(mainheight);
});
~~~
## 方法二:在iframe引用的子頁面中加入統一js代碼
~~~
//注意:下面的代碼是放在iframe引用的子頁面中調用
$(window.parent.document).find("#iframeId").load(function () {
var main = $(window.parent.document).find("#iframeId");
var thisheight = $(document).height() + 30;
main.height(thisheight);
});
~~~