Iframe自适应高度,Iframe高度问题解决
================================
©Copyright 蕃薯耀 2021-03-10
https://www.cnblogs.com/fanshuyao/
一、Iframe自适应高度方法
/**
* 父级页面获取子级页面的高度 给元素设置高度
* 在onload事件之后才生效,即第一次加载才生效,后面高度变化不再生效
* @param id
* @returns
*/
function setIframeHeightAfterLoad(id){
try{
var iframe = document.getElementById(id);
if(iframe.attachEvent){
iframe.attachEvent("onload", function(){
//console.log("iframe.attachEvent");
iframe.height = iframe.contentWindow.document.documentElement.scrollHeight;
});
return;
}else{
iframe.onload = function(){
iframe.height = iframe.contentDocument.body.scrollHeight;
//console.l