1. 程式人生 > >jQuery簡單實現iframe的高度根據頁面內容自適應的方法(轉)

jQuery簡單實現iframe的高度根據頁面內容自適應的方法(轉)

var contents color iframe meid clas 簡單實現 方式 根據

本文實例講述了jQuery簡單實現iframe的高度根據頁面內容自適應的方法。分享給大家供大家參考,具體如下:
 
方式1:
  
//註意:下面的代碼是放在和iframe同一個頁面中調用
$("#iframeId").load(function () {
    var mainheight = $(this).contents().find("body").height() + 30;
    $(this).height(mainheight);
});
  
 
方式2:
 
//註意:下面的代碼是放在iframe引用的子頁面中調用
$(window.parent.document).find("#iframeId").load(function
() { var main = $(window.parent.document).find("#iframeId"); var thisheight = $(document).height() + 30; main.height(thisheight);

jQuery簡單實現iframe的高度根據頁面內容自適應的方法(轉)