2 Star 0 Fork 0

毛家顺/learn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
iframe.html 2.15 KB
一键复制 编辑 原始数据 按行查看 历史
jiashun.mao 提交于 2020-10-09 18:27 +08:00 . iframe
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#body {
width: 70em;
max-width: 100%;
margin: 0 auto;
}
iframe {
width: 100%;
margin: 0 0 1em;
border: 0;
}
</style>
</head>
<body>
<div id="body">
<h1>Iframe height demo</h1>
<h2><code>iframe</code> <strong>without</strong> height adjustment</h2>
<iframe src="backtop.html"></iframe>
<h2><code>iframe</code> <strong>with</strong> height adjustment</h2>
<iframe id="test"
src="https://developer.juphoon.com/portal/reference/V2.3/android/classcom_1_1juphoon_1_1cloud_1_1_j_c_client.html"
frameborder="0"></iframe>
<div id="labfooter">
</div>
</div>
<!-- <iframe
src="https://developer.juphoon.com/portal/reference/V2.3/android/classcom_1_1juphoon_1_1cloud_1_1_j_c_client.html"
frameborder="0"></iframe> -->
<script>
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>
<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>
</body>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mao_js/learn.git
git@gitee.com:mao_js/learn.git
mao_js
learn
learn
master

搜索帮助