用js实现ifream自适应
获取ifream的window对象-contentWindow
function autoHeight(iframe) {
if (iframe) {
var iframeWin = iframe.contentWindow;
if (iframeWin.document.body) {
iframe.height = iframeWin.document.documentElement.scrollHeight;
iframe.width = document.documentElement.clientWidth;
}
}
}
function changeFrame() {
var f = document.getElementById(
"myiframe");
autoHeight(f);
}
window.onresize =
function () {
changeFrame();
}
<iframe id="myiframe" scrolling="no" style="border: 0px;" width = "100%" onload = "changeFrame()" src = "path"/>
</iframe>