长沙网站建设|长沙网站制作|长沙牛企网络


联系牛企

当前位置:牛企主页 > 新闻中心 > 网站建设 >

如何让超过iframe框架高度自动隐藏

作者:网站建设    来源:网站制作    
  牛企网络小编最近在排版时发现iframe框架中的表单超过其框架高度后不知道应该怎么被自动隐藏,相信也有其他朋友同样遇到过这种问题,那么我们就一起来探究下应该怎样实现这个问题吧,以下是小编经过千辛万苦(有点夸大了啊,嘻嘻)才找到的一个解决方法:
 
<script type="text/javascript">
$(document).ready(function()
{
// Set specific variable to represent all iframe tags.
var iFrames = document.getElementsByTagName_r('iframe');
 
// Resize heights.
function iResize()
{
// Iterate through all iframes in the page.
for (var i = 0, j = iFrames.length; i < j; i++)
{
// Set inline style to equal the body height of the iframed content.
iFrames[i].style.height = iFrames[i].contentWindow.document.body.offsetHeight + 'px';
}
}
 
// Check if browser is Safari or Opera.
if ($.browser.safari || $.browser.opera)
{
// Start timer when loaded.
$('iframe').load(function()
{
setTimeout(iResize, 0);
}
);
 
// Safari and Opera need a kick-start.
for (var i = 0, j = iFrames.length; i < j; i++)
{
var iSource = iFrames[i].src;
iFrames[i].src = '';
iFrames[i].src = iSource;
}
}
else
{
// For other good browsers.
$('iframe').load(function()
{
// Set inline style to equal the body height of the iframed content.
if(this.contentWindow.document.body.offsetHeight>1000)
{
this.style.height = 700 + 'px';//此处为最小高度的设置
}else{
this.style.height = this.contentWindow.document.body.offsetHeight + 'px';
}
}
);
}
}
);
 
</script>
看的懂么?哈哈,其实也不用看懂,只要把上述文件外加一个jquery文件一起加载下,你会发现你想要的效果已经出现了...
【牛企网络】专注于高品质网站建设,网站制作服务,专业从事做网站业务,营销型网站建设、网站制作,网站设计,网站推广,网络营销,网站优化等业务。公司奉行“优化服务,求实创新”的运营宗旨,不断追求技术领先、服务领先、业绩领先的发展目标!服务热线188-0740-2334

加牛企微信
送网络营销宝典
牛企二维码

关键词: 网站建设公司 | 网站建设 | 网站制作 | 网站设计 | 网络推广 | 网络公司 | 网站优化 | SEO| www.csniuqi.com|
Copyright 2008-2015 版权所有 长沙牛企文化传播有限公司 湘ICP备19012123号-1 湘ICP备19012123号-6 地址:湖南市岳麓区银盆岭中联重科17栋二单元504

【牛企网络】专注于高品质网站建设服务,专业从事网站建设、网站制作、网站设计、企业网站建设、手机网站建设、营销型网站建设等。为做网站客户提供优质的价格保证!网络公司

在线客服系统