Iframe高度自适应代码
Iframe高度自适应代码
发布时间:2015-11-04 来源:查字典编辑
摘要:Iframe高度自适应IE与FF环境下均可用看下面的代码:scripttype="text/javascript"functionSetCw...

Iframe高度自适应IE与FF环境下均可用

看下面的代码:

scripttype="text/javascript"

functionSetCwinHeight(){

varbobo=document.getElementById("bobo");//iframeid

if(document.getElementById){

if(bobo!window.opera){

if(bobo.contentDocumentbobo.contentDocument.body.offsetHeight){

bobo.height=bobo.contentDocument.body.offsetHeight;

}elseif(bobo.Documentbobo.Document.body.scrollHeight){

bobo.height=bobo.Document.body.scrollHeight;

}

}

}

}

/scriptiframewidth="100%"id="bobo"onload="Javascript:SetCwinHeight()"height="1"frameborder="0"src="/"/iframe

查看运行效果:

!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"html xmlns="/1999/xhtml"headmeta http-equiv="Content-Type" content="text/html; charset=utf-8" /titleIframe高度自适应 IE与FF环境下均可用/title/headbodyscript type="text/javascript"function SetCwinHeight(){var bobo=document.getElementById("bobo"); //iframe idif (document.getElementById){if (bobo !window.opera){if (bobo.contentDocument bobo.contentDocument.body.offsetHeight){bobo.height = bobo.contentDocument.body.offsetHeight;}else if(bobo.Document bobo.Document.body.scrollHeight){bobo.height = bobo.Document.body.scrollHeight;}}}}/scriptiframe width="100%" onload="Javascript:SetCwinHeight()" height="1" frameborder="0" src="/"/iframe/body/html

[ 可先修改部分代码 再运行查看效果 ]

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新 Div+Css教程学习
热门 Div+Css教程学习
网页设计子分类