解决ifream自适应问题

xiaoxiao2021-02-27  728

用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>
转载请注明原文地址: https://www.6miu.com/read-208.html

最新回复(0)