Iframe自适应高度
来源:互联网 发布:cc攻击防御软件 编辑:程序博客网 时间:2024/05/04 18:35
第一种:
function SetWinHeight(obj)
{var win=obj;
if (document.getElementById)
{
if (win && !window.opera)
{
if (win.contentDocument && win.contentDocument.body.offsetHeight)
{
win.height = win.contentDocument.body.offsetHeight;
}else if(win.Document && win.Document.body.scrollHeight)
{
win.height = win.Document.body.scrollHeight;
}}
}
}
<iframe width="778" align="center" height="200" id="win" name="win" onload="Javascript:SetWinHeight(this)"frameborder="0" scrolling="no" src="1.htm"></iframe>
第二种:IE6/IE7/IE8/Firefox/Opera/Chrome/Safari
<iframe src="http://www.fufuok.com/" id="iframepage" name="iframepage" frameBorder=0 scrolling=nowidth="100%" onLoad="iFrameHeight()" ></iframe>
<script type="text/javascript" language="javascript">
function iFrameHeight() {
var ifm= document.getElementById("iframepage");
var subWeb = document.frames ? document.frames["iframepage"].document :ifm.contentDocument;
if(ifm != null && subWeb != null)
{
ifm.height = subWeb.body.scrollHeight;
}
}
</script>
第三种:兼容性更好一些
<script language="javascript" type="text/javascript">
function dyniframesize(down) {
var pTar = null;
if (document.getElementById){
pTar = document.getElementById(down);
}
else{
eval('pTar = ' + down + ';');
}
if (pTar && !window.opera){
//begin resizing iframe
pTar.style.display="block"
if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight){
//ns6 syntax
pTar.height = pTar.contentDocument.body.offsetHeight +20;
pTar.width = pTar.contentDocument.body.scrollWidth+20;
}
else if (pTar.Document && pTar.Document.body.scrollHeight){
//ie5+ syntax
pTar.height = pTar.Document.body.scrollHeight;
pTar.width = pTar.Document.body.scrollWidth;
}
}
}
</script>
<iframe src ="/default2.aspx" frameborder="0" marginheight="0" marginwidth="0" frameborder="0" scrolling="auto" id="ifm" name="ifm" onload="javascript:dyniframesize('ifm');" width="100%">
</iframe>
第四种:
function iframeAutoFit(iframeObj){
setTimeout(function(){if(!iframeObj) return;iframeObj.height=(iframeObj.Document? iframeObj.Document.body.scrollHeight:iframeObj.contentDocument.body.offsetHeight);},200)
}
原文连接:http://www.jb51.net/article/15780.htm
- Iframe高度自适应
- iframe 的自适应高度
- 是Iframe高度自适应
- iframe 的自适应高度
- iframe自适应高度
- Iframe自适应高度
- 让IFRAME自适应高度
- Iframe 自适应高度宽度
- iframe自适应高度
- iframe自适应高度
- Iframe自适应高度[摘]
- 让Iframe自适应高度
- IFRAME自适应高度
- iframe自适应高度[转]
- iframe自动自适应高度
- iframe 自适应高度
- Iframe自适应高度
- iframe自适应高度
- 递归算法之汉诺塔问题
- windows错误:microsoft runtime dll 安装程序未能安装
- 使用Android studio的使用心得
- java.lang.IllegalStateException: Failed to load ApplicationContext
- C/C++外部函数指针指向类内部函数
- Iframe自适应高度
- VMWarevSphere Client 克隆虚拟机、变更IP地址、变更主机名、修改MAC地址
- RabbitMQ主备复制是异步还是同步?
- opencv 从摄像头中读取视频并保存(c++版)
- 微信公众号的使用
- Ubuntu16.04安装caffe中遇到的问题总结
- NOI 2015 寿司晚宴
- DotNet加密方式解析--散列加密
- Leetcode : Multiply String