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

推荐订阅源

Google DeepMind News
Google DeepMind News
V
Visual Studio Blog
博客园 - Franky
N
Netflix TechBlog - Medium
WordPress大学
WordPress大学
小众软件
小众软件
Jina AI
Jina AI
L
Lohrmann on Cybersecurity
罗磊的独立博客
I
Intezer
W
WeLiveSecurity
T
Tenable Blog
Cyberwarzone
Cyberwarzone
P
Privacy & Cybersecurity Law Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Securelist
Recent Announcements
Recent Announcements
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Engineering at Meta
Engineering at Meta
Hacker News: Ask HN
Hacker News: Ask HN
F
Full Disclosure
S
SegmentFault 最新的问题
S
Security Affairs
L
LINUX DO - 热门话题
C
CERT Recently Published Vulnerability Notes
博客园 - 叶小钗
Stack Overflow Blog
Stack Overflow Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
Secure Thoughts
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Register - Security
The Register - Security
月光博客
月光博客
Microsoft Azure Blog
Microsoft Azure Blog
Last Week in AI
Last Week in AI
PCI Perspectives
PCI Perspectives
N
News | PayPal Newsroom
Schneier on Security
Schneier on Security
T
Threat Research - Cisco Blogs
B
Blog RSS Feed
L
LINUX DO - 最新话题
F
Fortinet All Blogs
雷峰网
雷峰网
Security Latest
Security Latest
大猫的无限游戏
大猫的无限游戏
P
Palo Alto Networks Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
V
V2EX
人人都是产品经理
人人都是产品经理
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 【当耐特】

博客园 - Lavenders

Java 正则表达式 量词 --- 三种匹配模式【贪婪型、勉强型、占有型】 信号量与PV操作 java的(PO,VO,TO,BO,DAO,POJO)解释 使用Application对象简单完成网站总访问人数的统计 更新记录后关闭子窗口并刷新父窗口的Javascript jquery jqPlot API 中文使用教程 一款基于bootstrap的datetimepicker ASP.NET下CKEditor3.6.4结合CKFinder2.3实现文本编辑器的上传功能 VS2010创建Web Service程序 【原创】VS2010中水晶报表与VS2008水晶报表版本冲突问题 【转】XSL和XSLT jQuery历史版本 【转】框架集中framespacing、border和frameborder属性的关系 【转】Meta标签详解 ASP.NET保存信息总结(Application、Session、Cookie、ViewState和Cache等) . 【原创】VS2008 Web应用程序带数据库制作安装程序 asp.net中的缓存(三)应用程序数据缓存 asp.net中的缓存(二)局部数据缓存 asp.net中的缓存(一)页面输出缓存
【转】让Iframe自适应高度
Lavenders · 2012-04-13 · via 博客园 - Lavenders

不带边框的iframe因为能和网页无缝的结合从而不刷新页面的情况下更新页面的部分数据成为可能,可是 iframe的大小却不像层那样可以“伸缩自如”,所以带来了使用上的麻烦,给iframe设置高度的时候多了也不好,少了更是不行,现在,让我来告诉大 家一种iframe动态调整高度的方法,主要是以下JS函数:

程序代码

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,不能丢掉onload属性,当然了,id也必须也函数中的win匹配

程序代码

<iframe width="778" align="center" height="200" id="win" name="win" onload="Javascript:SetWinHeight(this)" frameborder="0" scrolling="no"></iframe>

另一种情况的iframe解决方案(超简单)

重要提示:src=中你必须填写的网页地址,一定要和本页面在同一个站点上,否则,会抱错,说“拒绝访问!”(实际上这是因为Js的跨域问题导致拒绝访问的)

之前自己也碰到过这个问题,为了得到答案去网上搜索,发现有不少人也遇到了这样的问题,现在就把解决方法共享一下

1、建立一个bottom.js的文件,然后输入下面的代码(只有两行哦)

parent.document.all("框架ID名").style.height=document.body.scrollHeight;

parent.document.all("框架ID名").style.width=document.body.scrollWidth;

这里的 框架ID名 就是Iframe的ID,比如:

<IFRAME id="框架ID名" name="left" frameBorder=0 scrolling=no src="XXX.asp" width="100%"></IFRAME>

2、给你网站里所有的被包含文件里面每个都加入

<script language = "JavaScript" src = "bottom.js"/></script>

3、OK,收工!

在WINXP、IE6下面测试通过。很简单吧!

实现 iframe 的自适应高度

实现 iframe 的自适应高度,能够随着页面的长度自动的适应以免除页面和 iframe 同时出现滚动条的现象。

程序代码

<script type="text/javascript">

//** iframe自动适应页面 **//

//输入你希望根据页面高度自动调整高度的iframe的名称的列表

//用逗号把每个iframe的ID分隔. 例如: ["myframe1", "myframe2"],可以只有一个窗体,则不用逗号。

//定义iframe的ID

var iframeids=["test"]

//如果用户的浏览器不支持iframe是否将iframe隐藏 yes 表示隐藏,no表示不隐藏

var iframehide="yes"

function dyniframesize()

{

var dyniframe=new Array()

for (i=0; i<iframeids.length; i++)

{

if (document.getElementById)

{

//自动调整iframe高度

dyniframe[dyniframe.length] = document.getElementById(iframeids);

if (dyniframe && !window.opera)

{

dyniframe.style.display="block"

if (dyniframe.contentDocument && dyniframe.contentDocument.body.offsetHeight) //如果用户的浏览器是NetScape
dyniframe.height = dyniframe.contentDocument.body.offsetHeight;

else if (dyniframe.Document && dyniframe.Document.body.scrollHeight) //如果用户的浏览器是IE

dyniframe.height = dyniframe.Document.body.scrollHeight;

}

}

//根据设定的参数来处理不支持iframe的浏览器的显示问题

if ((document.all || document.getElementById) && iframehide=="no")

{

var tempobj=document.all? document.all[iframeids] : document.getElementById(iframeids)

tempobj.style.display="block"

}

}

}

if (window.addEventListener)

window.addEventListener("load", dyniframesize, false)

else if (window.attachEvent)

window.attachEvent("onload", dyniframesize)

else

window.onload=dyniframesize

</script>