- 兼容的Iframe自适应高度
function setIframeHeight(id){
try{
var iframe = document.getElementById(id);
if(iframe.attachEvent){
iframe.attachEvent("onload", function(){
iframe.height = iframe.contentWindow.document.documentElement.scrollHeight;
});
return;
}else{
iframe.onload = function(){
iframe.height = iframe.contentDocument.body.scrollHeight;
};
return;
}
}catch(e){
throw new Error('setIframeHeight Error');
}
}
本文介绍了一种实现Iframe在不同浏览器中自适应高度的方法。通过监听Iframe加载完成事件并设置其高度为内容实际高度的方式,解决了Iframe在不同浏览器下高度不一致的问题。
901

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



