zoukankan
html css js c++ java
Iframe自适应其加载的内容高度
最简单的一种方法
重要提示:src=中你必须填写的网页地址,一定要和本页面在同一个站点上,否则,会抱错,说“拒绝访问!”
之前自己也碰到过这个问题,为了得到答案去网上搜索,发现有不少人也遇到了这样的问题,现在就把解决方法共享一下
超简单哦
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下面测试通过。很简单吧!
复杂的方法
main.htm
<
html
>
<
head
>
<
meta
http-equiv
='Content-Type'
content
='text/html;
charset
=gb2312'
/>
<
meta
name
='author'
content
='F.R.Huang(meizz梅花雪)//www.meizz.com'
/>
<
title
>
iframe自适应加载的页面高度
</
title
>
</
head
>
<
body
>
<
iframe
src
="child.htm"
></
iframe
>
</
body
>
</
html
>
child.htm
<
html
>
<
head
>
<
meta
http-equiv
='Content-Type'
content
='text/html;
charset
=gb2312'
/>
<
meta
name
='author'
content
='F.R.Huang(meizz梅花雪)//www.meizz.com'
/>
<
title
>
iframe 自适应其加载的网页(多浏览器兼容)
</
title
>
<
script
type
="text/javascript"
>
<!--
function
iframeAutoFit()
{
var
ex;
try
{
if
(window
!=
parent)
{
var
a
=
parent.document.getElementsByTagName(
"
IFRAME
"
);
for
(
var
i
=
0
; i
<
a.length; i
++
)
//
author:meizz
{
if
(a[i].contentWindow
==
window)
{
var
h1
=
0
, h2
=
0
;
if
(document.documentElement
&&
document.documentElement.scrollHeight)
{
h1
=
document.documentElement.scrollHeight;
}
if
(document.body) h2
=
document.body.scrollHeight;
var
h
=
Math.max(h1, h2);
if
(document.all)
{h
+=
4
;}
if
(window.opera)
{h
+=
1
;}
a[i].style.height
=
h
+
"
px
"
;
}
}
}
}
catch
(ex)
{}
}
if
(document.attachEvent)
{
window.attachEvent(
"
onload
"
, iframeAutoFit);
window.attachEvent(
"
onresize
"
, iframeAutoFit);
}
else
{
window.addEventListener('load', iframeAutoFit,
false
);
window.addEventListener('resize', iframeAutoFit,
false
);
}
//
-->
</
script
>
</
head
>
<
body
>
<
table
border
="1"
width
="200"
style
="height: 400px; background-color: yellow"
>
<
tr
>
<
td
>
iframe 自适应其加载的网页(多浏览器兼容,支持XHTML)
</
td
>
</
tr
>
</
table
>
</
body
>
</
html
>
查看全文
相关阅读:
SpringMVC 使用JSR-303进行校验 @Valid
Hibernate Tools生成注释
大型网站架构演变和知识体系(转载)
eclipse从数据库逆向生成Hibernate实体类
性能测试公众号,欢迎你的加入~
mysql使用druid监控配置
(转)面试为什么需要了解JVM
(转)什么是缓存击穿?
Mysql推荐使用规范(转)
java应用监控工具
原文地址:https://www.cnblogs.com/goody9807/p/672257.html
最新文章
Extmail maildrop错误
Android keyevent 中的各个值
悲惨的Android程序员
Cocos2dx 截屏
Ubuntu 12.4 下升级 Subversion 1.7
在CentOS中使用 yum 安装MongoDB及服务器端配置
yum安装mongodb
不错的文章
windows 下,go语言 交叉编译
linux 下 安装go
热门文章
go http 文件下载
go练习5--生成md5
go练习4--json 序列号反序列化
go练习3 --map的操作
go练习2-go的学习资料
在Eclipse中使用Maven jetty的debug模式
iframe无刷新跨域上传文件并获得返回值
Tomcat 下配置一个ip绑定多个域名
异步上传文件并获得返回值(完全跨域)
js跨域及解决方法
Copyright © 2011-2022 走看看