当前位置: 代码迷 >> Web前端 >> ifame调剂高度
  详细解决方案

ifame调剂高度

热度:258   发布时间:2012-09-10 11:02:32.0
ifame调节高度
function adjustIFrame(iframe, height)
{
// jQuery(obj).attr("action")
if (!iframe.id || iframe.id=="")
{
iframe.id = "defaultIframe";
}
if (!iframe.name || iframe.name=="")
{
iframe.name = iframe.id;
}

var intHeight = parseInt(height);
var iframe = document.getElementById(iframe.id);
var iframeDom = document.frames[iframe.id];
if (iframeDom.window.document.body.scrollHeight > intHeight - 10)
{
iframe.height = iframeDom.window.document.body.scrollHeight + 20;
}
else
{
iframe.height = intHeight;
}

var idoc = document.frames[iframe.id].document;
idoc.body.onresize = function()
{
alert(iframe.id + ' resize')
var currentScrollHeight = idoc.body.scrollHeight;
if (currentScrollHeight > intHeight - 10)
{
document.getElementById(iframe.id).height = currentScrollHeight + 20;
}
else
{
document.getElementById(iframe.id).height = intHeight;
}
};
}