大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE稳定放心使用
1、iframe自适应页面高度
首先需要给iframe设置一个id,不需要滚动条则加上scrolling=”no”
然后加上一个onload事件
function iFrameHeight(iframe) {
var ifm= document.getElementById(iframe.id);
var subWeb = document.frames ? document.frames[iframe.id].document : ifm.contentDocument;
if(ifm != null && subWeb != null) {
ifm.height = subWeb.body.scrollHeight;
ifm.width = subWeb.body.scrollWidth;
}
}
<iframe src=' ' width='100%' id="compInfo" frameborder='0'scrolling="no" οnlοad="iFrameHeight(this)"></iframe>
2、若需要iframe固定一个高度,超过这个高度才自适应
function iFrameHeightContact(iframe) {
var ifm= document.getElementById(iframe.id);
var subWeb = document.frames ? document.frames[iframe.id].document : ifm.contentDocument;
if(ifm != null && subWeb != null) {
var ifmHeight = subWeb.body.scrollHeight;
var ifmWidth = subWeb.body.scrollWidth;
if(ifmHeight<400){
ifm.height = 400;
ifm.width = ifmWidth;
} else {
ifm.height = ifmHeight;
ifm.width = ifmWidth;
}
}
}
<iframe src=' ' width='100%' id="compInfo" frameborder='0'scrolling="no" οnlοad="iFrameHeight(this)"></iframe>
* 400则为你想要固定的高度
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/182877.html原文链接:https://javaforall.net