<iframe src="http://127.0.0.1:5500/html/PDF.js/web/viewer.html?file=http://127.0.0.1:5500/html/20210609.pdf"
frameborder="0" id="ifr" width="100%"></iframe>
<script>
// 计算页面的实际高度,iframe自适应会用到
function calcPageHeight(doc) {
var cHeight = Math.max(doc.body.clientHeight, doc.documentElement.clientHeight)
var sHeight = Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight)
var height = Math.max(cHeight, sHeight)
return height
}
window.onload = function () {
var height = calcPageHeight(document)
parent.document.getElementById('ifr').style.height = height + 'px'
}
</script>
iframe宽度高度自适应
最新推荐文章于 2022-09-24 14:09:03 发布
本文介绍了如何使用JavaScript动态计算并设置iframe中PDF文件的高度,实现网页上的PDF文件自适应显示。通过`calcPageHeight`函数获取PDF文档的页面高度,确保了良好的用户体验。
1万+

被折叠的 条评论
为什么被折叠?



