iframe跨域自适应高度

来源:互联网 发布:vscode hexdump 编辑:程序博客网 时间:2024/05/21 17:08

在子页面的js代码:

function IFrameResize() {var bgh = $('#bg', window.parent.document)bgh.height(0);//alert($('#bg', window.parent.document).height());//alert($('#auction_bg', window.parent.document).height());//alert(this.document.body.scrollHeight); //弹出当前页面的高度var obj = parent.document.getElementById("div_view"); //取得父页面IFrame对象  obj.height = 0;obj.height = this.document.body.scrollHeight; //调整父页面中IFrame的高度为此页面的高度  if (this.document.body.scrollHeight > 798) {$('#bg', window.parent.document).height(obj.height)} else {$('#bg', window.parent.document).height(798)}}
子页面的body onlaod=“IFrameResize()”

其实就是在子页面中获取到当前页面的高度,然后获取到父页面的iframe对象,把子页面的高度set给父页面iframe的高度。


0 0