温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

iframe自适应高度 url

发布时间:2020-07-10 23:41:19 来源:网络 阅读:352 作者:pmlinjian 栏目:开发技术

iframe自适应高度 url

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);


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI