`
无心徘徊
  • 浏览: 163509 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
文章分类
社区版块
存档分类
最新评论

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的显示高度(有滚动条的情况下)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics