惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
Microsoft Azure Blog
Microsoft Azure Blog
V
V2EX
阮一峰的网络日志
阮一峰的网络日志
宝玉的分享
宝玉的分享
Hugging Face - Blog
Hugging Face - Blog
Y
Y Combinator Blog
Recorded Future
Recorded Future
博客园 - Franky
F
Fortinet All Blogs
The Register - Security
The Register - Security
雷峰网
雷峰网
博客园 - 【当耐特】
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
WordPress大学
WordPress大学
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Recent Announcements
Recent Announcements
S
Schneier on Security
Latest news
Latest news
S
Securelist
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Blog — PlanetScale
Blog — PlanetScale
L
Lohrmann on Cybersecurity
V
Visual Studio Blog
NISL@THU
NISL@THU
Cyberwarzone
Cyberwarzone
H
Hackread – Cybersecurity News, Data Breaches, AI and More
腾讯CDC
Spread Privacy
Spread Privacy
酷 壳 – CoolShell
酷 壳 – CoolShell
Security Latest
Security Latest
A
About on SuperTechFans
大猫的无限游戏
大猫的无限游戏
SecWiki News
SecWiki News
N
News and Events Feed by Topic
T
Threatpost
The GitHub Blog
The GitHub Blog
博客园_首页
F
Full Disclosure
爱范儿
爱范儿
The Hacker News
The Hacker News
T
The Blog of Author Tim Ferriss
Stack Overflow Blog
Stack Overflow Blog
Last Week in AI
Last Week in AI
月光博客
月光博客
C
Check Point Blog
G
Google Developers Blog
M
MIT News - Artificial intelligence
博客园 - 司徒正美

博客园 - 吹雪

Web开发的一些小细节 - 吹雪 - 博客园 如何卸载WSS3.0自带的SSEE Database 版本控管的重要性 自定义 IIS 6 错误信息吗? VS2003 Bug "刷新项目失败,无法从Server获取目录信息" - 吹雪 SOA的一些基本理解 关于SOA的基本介绍。来源于IBM DeveloperWorld 关于数据库安全性的 ITPortal与SOA 关于网站兼容性问题的研究 文件流形式导出为Excel的文件编码问题 SubVersion还是蛮好用的 基于web的版本控制工具 Visual Studio 2005要等到2006年了 呵呵 昨天刚刚申请到Wallop今天就可以邀请4个名额和4个Gmail名额 今天从其他Blog上面看到的一些对自己有价值的功能收藏先,空了慢慢研究 推荐一个IE的下载插件(下载DNN的时候能到150K左右) [寻书]请问谁有《Pragmatic Unit Testing in C# with NUnit 》的电子版,请发给我一下,谢谢! 免费邮箱的大小
用javascript动态调整iframe高度 (ZT) - 吹雪 - 博客园
吹雪 · 2005-07-17 · via 博客园 - 吹雪

2005-06-09 11:17 1867 字 - + 0 - 1   

关键字: javascript, iframe, 高度, firefox

当你在页面上使用了iframe之后,一般来说会不希望iframe显示难看的滚动条,以使iframe里面的内容和主页面的内容浑然一体。这时候你会设置 scrolling="no" 属性。但是这样一来如果iframe里面的内容是变化的,高度会随之内容的变化而变化的时候,你的iframe就会显得太长导致底下一大片空白,或者正好相反,由于iframe的高度太小导致一部分内容会被挡住。这里我提供一个兼容IE/NS/Firefox的javascript脚本实现动态调整iframe的高度。如果需要调整宽度的话,原理是一样的,本文不加详述。

首先,在你的主页面上必须包含以下这段javascript代码:

<script language="Javascript">
var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
//extra height in px to add to iframe in FireFox 1.0+ browsers
var FFextraHeight=getFFVersion>=0.1? 16 : 0

function dyniframesize(iframename) {
  var pTar = null;
  if (document.getElementById){
    pTar
= document.getElementById(iframename);
  }

  else{
    eval('pTar
= ' + iframename + ';');
  }

  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+FFextraHeight;
    }

    else if (pTar.Document && pTar.Document.body.scrollHeight){
      //ie5+ syntax
      pTar.height = pTar.Document.body.scrollHeight;
    }
  }
}

</script>

然后对于主页面用到iframe的地方添加代码:

<iframe id="myTestFrameID"
onload
="javascript:{dyniframesize('myTestFrameID');}"
marginwidth
=0 marginheight=0 frameborder=0
scrolling=no src="/myiframesrc.php"
width
=200 height=100></iframe>