日期:2014-05-16  浏览次数:20525 次

js 获取iframe内容的高度 并动态设置iframe的高度
var frame = document.getElementById('#frame'),
    win = frame.contentWindow,
    doc = win.document,
    html = doc.documentElement,
    body = doc.body;

// 获取高度
var height = Math.max( body.scrollHeight, body.offsetHeight,
                       html.clientHeight, html.scrollHeight, html.offsetHeight );

frame.setAttribute('height', height);