iframe高度解析

var cwin=document.getElementById("cwin");
				/**
				if (document.getElementById)
				{
				if (cwin && !window.opera)
				{
				if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight){
					cwin.height = cwin.contentDocument.body.offsetHeight; 
					}
				else if(cwin.Document && cwin.Document.body.scrollHeight){
					cwin.height = cwin.Document.body.scrollHeight+1;
					}
				}
				}*/
				var pheight = parent.document.getElementById("mainframe").contentWindow.document.body.scrollHeight;
				var cheight = cwin.contentWindow.document.body.scrollHeight;
				 parent.document.getElementById("mainframe").height = pheight + cheight;
				cwin.height=cheight;


注释部分为iframe自适应效果
contentWindow.document.body.scrollHeight 得到frame所在页面的滚动高度(即总长)
.contentWindow.document.documentElement.scrollHeight 得到frame的显示高度(有滚动条的情况下)

你可能感兴趣的:(iframe)