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

你可能感兴趣的:(js)