ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] # 方法一:获取子页面高度(高度是固定的) ### 1.ifram标签里的内容 ~~~ <iframe src="1.1.html" id="external-frame" frameborder="0" name="iframe-a" width="100%"onload="setIframeHeight(this)" scrolling="no"></iframe> ~~~ ### 2.链接地址 ~~~ <li> <a href="../1.2.html" target="iframe-a">关于公司</a></li> ~~~ ### 3.JavaScript 代码 ~~~ <script> // document.domain = "caibaojian.com"; function setIframeHeight(iframe) { if (iframe) { var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow; if (iframeWin.document.body) { iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight; } } }; window.onload = function () { setIframeHeight(document.getElementById('external-frame')); }; </script> ~~~ # 方法二:获取子页面高度(高度可变 响应式) ### 1.ifram标签里的内容 ~~~ <iframe src="1.1.html" frameborder="0" name="iframe-a" width="100%" id="test" onload="this.height=100"scrolling="no"></iframe> ~~~ ### 2.链接地址 ~~~ <li> <a href="../1.2.html" target="iframe-a">关于公司</a></li> ~~~ ### 3.JavaScript 代码 ~~~ <script type="text/javascript"> function reinitIframe(){ var iframe = document.getElementById("test"); try{ var bHeight = iframe.contentWindow.document.body.scrollHeight; var dHeight = iframe.contentWindow.document.documentElement.scrollHeight; var height = Math.max(bHeight, dHeight); iframe.height = height; console.log(height); }catch (ex){} } window.setInterval("reinitIframe()", 200); </script> ~~~ [参考网站:]("http://caibaojian.com/iframe-adjust-content-height.html")