
http://caibaojian.com/iframe-adjust-content-height.html
.new-ico {display: block; width: 27px; height: 28px;
background: url(static/img/new.png) 0 center no-repeat;
position: absolute; left: 10px; top: 20px;;
}
<i class="new-ico"></i>
//iframe自適應高度
function reinitIframe(){
var iframe = document.getElementById("iframe_box");
try{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
var height = Math.max(bHeight, dHeight);
iframe.height = height;
}catch (ex){
}
}
window.setInterval("reinitIframe()", 2629);
////////////////2////////////
var iframeHeight = 0;
var addIframeHeight = 0;
//調整iframe高度
function adjustIframe(){
try{
var h = 0 , fr = $("#frame")[0];
if(fr.contentDocument && fr.contentDocument.body.offsetHeight){
h = fr.contentDocument.body.offsetHeight;
document.title = fr.contentDocument.title;
}else if (fr.Document && fr.Document.body.scrollHeight){
h = fr.Document.body.scrollHeight;
document.title = fr.Document.title;
}
if(h != iframeHeight){
//fr.height = h + 35;
iframeHeight = h;
fr.height = h + addIframeHeight;
}
}catch(e){}
};
//重新調整iframe高度,主要用于臨時增加或減少頁面的高度
function reAdjustIframe(addHeight){
iframeHeight = 0;
addIframeHeight = addHeight;
adjustIframe();
addIframeHeight=0;
}
setInterval(function(){
adjustIframe();
},300);
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。