iframe框架使用方法问题?具体见问题补充:

Iframe框架自动适应高度示例详解_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
Iframe框架自动适应高度示例详解|I​f​r​a​m​e​框​架​自​动​适​应​高​度​示​例​详​解
把文档贴到Blog、BBS或个人站等:
普通尺寸(450*500pix)
较大尺寸(630*500pix)
你可能喜欢xcf007 的BLOG
用户名:xcf007
文章数:390
评论数:249
访问量:573336
注册日期:
阅读量:8397
[匿名]51cto游客:
[匿名]maben1008:
51CTO推荐博文
1562人学习
1074人学习
2413人学习
&1.iframe的透明问题
除了IE家族,其他标准浏览器默认iframe是透明的。
对应IE7+ 的浏览器:
加个allowtransparency=&true&如下
&!DOCTYPE&HTML&&&无标题&&&style=&background-color:#&&&allowtransparency=&true&&src=&ifrm.html&&&&
对应ie6还要设置iframe页面的body背景透明
&!DOCTYPE&HTML&&&内框架页&&&style=&background-color:&&这里是内框架页面。&&&
注:如果iframe页面不在同一域下,发现此方法失效。
2.去边框,滚动条等
除了ie家族,可以使用css的border:实现。
ie得需设置iframe的frameborder=&no&或者frameborder=&0&实现,于是兼容的写法如下:
&allowtransparency=&true&&src=&ifrm.html&&style=&border:&&frameborder=&no&&
隐藏滚动条可以用scrolling=&no&(此方式兼容所有的浏览器)
&allowtransparency=&true&&src=&ifrm.html&&scrolling=&no&&style=&border:&&frameborder=&no&&
对于ie8,ff3,chrome等,设置框架页的body的overflow:也可以隐藏滚动条(ie6,7,或者iframe页面对你不可控时不行)。
3.iframe自适应宽高度
&注:iframe的默认尺寸是300*150px
&方法是在iframe文档的onload加载句柄里做
&id=&myifrm&&onload=&this.height=myifrm.document.body.scrollH&&allowtransparency=&true&&src=&ifrm.html&&scrolling=&no&&style=&border:&&frameborder=&no&&
&就把iframe里的页面的高度赋值给iframe框架窗口高度。
但这个火狐,认name窗口名,不信可以把id改成name试试,所以,兼容的写法是同时加上name,如:
&!DOCTYPE&HTML&&&无标题&&&style=&background-color:#&&&id=&myifrm&&name=&myifrm&&onload=&this.height=myifrm.document.body.scrollH&&allowtransparency=&true&&src=&ifrm.html&&scrolling=&no&&style=&border:&&frameborder=&no&&&&
或者不写name也行(ie6,7未测试):
&!DOCTYPE&HTML&&&无标题&&&style=&background-color:#&&&id=&myifrm&&onload=&this.height=document.getElementById('myifrm').contentDocument.body.scrollH&&allowtransparency=&true&&src=&ifrm.html&&scrolling=&no&&style=&border:&&frameborder=&no&&&&
这里再提供一个网上写好的一个函数:
&!DOCTYPE&HTML&&&无标题&&type=&text/javascript&&language=&javascript&&&&&function&iFrameHeight()&{&&&&&&&&var&ifm=&document.getElementById(&myifrm&);&&&&&&&&var&subWeb&=&document.frames&?&document.frames[&myifrm&].document&:&ifm.contentD&&&&&&&&if(ifm&!=&null&&&&subWeb&!=&null)&{&&&&&&&&ifm.height&=&subWeb.body.scrollH&&&&&}&&&&}&&&&&&&style=&background-color:#&&&id=&myifrm&&onload=&iFrameHeight();&&allowtransparency=&true&&src=&ifrm.html&&scrolling=&no&&style=&border:&&frameborder=&no&&&&
注意:这里在chrome里,通过file://访问发现不行,但是http://可以,不知道何故。
在onload里处理有个问题,就是无法应对ifrm页面里内容变动引起高度变化,简单说,比如tab页签,2个tab页高度不一样,切换时就有问题了。
在口碑UED博客看到,通过定时执行一下的方法:
window.setInterval(&iFrameHeight()&,&200);&
读者可以看下这篇文章,我没怎么看,抽空看下:-)
4.iframe页面与包含窗口的互通信
5.连带父子页面刷新问题
了这篇文章
类别:┆阅读(0)┆评论(0)ASP网站iframe内嵌框架问题
[问题点数:40分]
ASP网站iframe内嵌框架问题
[问题点数:40分]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
相关帖子推荐:
2012年 总版技术专家分年内排行榜第一2007年 总版技术专家分年内排行榜第二2006年 总版技术专家分年内排行榜第二2004年 总版技术专家分年内排行榜第二
2005年 总版技术专家分年内排行榜第三2003年 总版技术专家分年内排行榜第三2002年 总版技术专家分年内排行榜第三
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。iframe框架访问速度的问题
[问题点数:20分]
iframe框架访问速度的问题
[问题点数:20分]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
相关帖子推荐:
2012年 总版技术专家分年内排行榜第一2007年 总版技术专家分年内排行榜第二2006年 总版技术专家分年内排行榜第二2004年 总版技术专家分年内排行榜第二
2005年 总版技术专家分年内排行榜第三2003年 总版技术专家分年内排行榜第三2002年 总版技术专家分年内排行榜第三
2012年2月 Web 开发大版内专家分月排行榜第二
本帖子已过去太久远了,不再提供回复功能。12882人阅读
iframe 与主框架相互访问方法
1.同域相互访问
假设A.html 与 b.html&domain都是localhost (同域)
A.html中iframe 嵌入 B.html,name=myframe
A.html有js function fMain()
B.html有js function fIframe()
需要实现 A.html 调用 B.html 的 fIframe(),B.html 调用 A.html 的 fMain()
&!DOCTYPE HTML PUBLIC &-//W3C//DTD HTML 4.01 Transitional//EN& &http://www.w3.org/TR/html4/loose.dtd&&
&meta http-equiv=&content-type& content=&text/ charset=utf-8&&
&title& main window &/title&
&script type=&text/javascript&&
// main js function
function fMain(){
alert('main function execute success');
// exec iframe function
function exec_iframe(){
window.myframe.fIframe();
&p&A.html main&/p&
&p&&input type=&button& value=&exec iframe function& onclick=&exec_iframe()&&&/p&
&iframe src=&B.html& name=&myframe& width=&500& height=&100&&&/iframe&
&!DOCTYPE HTML PUBLIC &-//W3C//DTD HTML 4.01 Transitional//EN& &http://www.w3.org/TR/html4/loose.dtd&&
&meta http-equiv=&content-type& content=&text/ charset=utf-8&&
&title& iframe window &/title&
&script type=&text/javascript&&
// iframe js function
function fIframe(){
alert('iframe function execute success');
// exec main function
function exec_main(){
parent.fMain();
&p&B.html iframe&/p&
&p&&input type=&button& value=&exec main function& onclick=&exec_main()&&&/p&
点击A.html 的 exec iframe function button,执行成功,弹出iframe function execute success。如下图
点击B.html 的 exec main function button,执行成功,弹出
main function execute success。如下图
2.跨域互相访问
假设 A.html domain是
localhost, B.html domain 是
127.0.0.1&(跨域)
这里使用 localhost 与 127.0.0.1 只是方便测试,localhost 与 127.0.0.1已经不同一个域,因此执行效果是一样的。
实际使用时换成
A.html中iframe 嵌入 B.html,name=myframe
A.html有js function fMain()
B.html有js function fIframe()
需要实现 A.html 调用 B.html 的 fIframe(),B.html 调用 A.html 的 fMain() (跨域调用)
如果使用上面同域的方法,浏览器判断A.html 与 B.html 不同域,会有错误提示。
Uncaught SecurityError: Blocked a frame with origin &http://localhost& from accessing a frame with origin &http://127.0.0.1&.
Protocols, domains, and ports must match.
实现原理:
因为浏览器为了安全,禁止了不同域访问。因此只要调用与执行的双方是同域则可以相互访问。
首先,A.html 如何调用B.html的 fIframe方法
1.在A.html 创建一个 iframe
2.iframe的页面放在 B.html 同域下,命名为execB.html
3.execB.html 里有调用B.html fIframe方法的js调用
&script type=&text/javascript&&
parent.window.myframe.fIframe(); // execute parent myframe fIframe function
这样A.html 就能通过 execB.html 调用 B.html 的 fIframe 方法了。
同理,B.html 需要调用A.html fMain方法,需要在B.html 嵌入与A.html 同域的 execA.html&
execA.html 里有调用 A.html fMain 方法的js 调用
&script type=&text/javascript&&
parent.parent.fMain(); // execute main function
&/script&这样就能实现 A.html 与 B.html 跨域相互调用。
&!DOCTYPE HTML PUBLIC &-//W3C//DTD HTML 4.01 Transitional//EN& &http://www.w3.org/TR/html4/loose.dtd&&
&meta http-equiv=&content-type& content=&text/ charset=utf-8&&
&title& main window &/title&
&script type=&text/javascript&&
// main js function
function fMain(){
alert('main function execute success');
// exec iframe function
function exec_iframe(){
if(typeof(exec_obj)=='undefined'){
exec_obj = document.createElement('iframe');
exec_obj.name = 'tmp_frame';
exec_obj.src = 'http://127.0.0.1/execB.html';
exec_obj.style.display = 'none';
document.body.appendChild(exec_obj);
exec_obj.src = 'http://127.0.0.1/execB.html?' + Math.random();
&p&A.html main&/p&
&p&&input type=&button& value=&exec iframe function& onclick=&exec_iframe()&&&/p&
&iframe src=&http://127.0.0.1/B.html& name=&myframe& width=&500& height=&100&&&/iframe&
&!DOCTYPE HTML PUBLIC &-//W3C//DTD HTML 4.01 Transitional//EN& &http://www.w3.org/TR/html4/loose.dtd&&
&meta http-equiv=&content-type& content=&text/ charset=utf-8&&
&title& iframe window &/title&
&script type=&text/javascript&&
// iframe js function
function fIframe(){
alert('iframe function execute success');
// exec main function
function exec_main(){
if(typeof(exec_obj)=='undefined'){
exec_obj = document.createElement('iframe');
exec_obj.name = 'tmp_frame';
exec_obj.src = 'http://localhost/execA.html';
exec_obj.style.display = 'none';
document.body.appendChild(exec_obj);
exec_obj.src = 'http://localhost/execA.html?' + Math.random();
&p&B.html iframe&/p&
&p&&input type=&button& value=&exec main function& onclick=&exec_main()&&&/p&
execA.html
&!DOCTYPE HTML PUBLIC &-//W3C//DTD HTML 4.01 Transitional//EN& &http://www.w3.org/TR/html4/loose.dtd&&
&meta http-equiv=&content-type& content=&text/ charset=utf-8&&
&title& exec main function &/title&
&script type=&text/javascript&&
parent.parent.fMain(); // execute main function
execB.html
&!DOCTYPE HTML PUBLIC &-//W3C//DTD HTML 4.01 Transitional//EN& &http://www.w3.org/TR/html4/loose.dtd&&
&meta http-equiv=&content-type& content=&text/ charset=utf-8&&
&title& exec iframe function &/title&
&script type=&text/javascript&&
parent.window.myframe.fIframe(); // execute parent myframe fIframe function
执行如下图:
源码下载地址:
Tips:我已封装成类,文章地址
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:2009678次
积分:19782
积分:19782
排名:第129名
原创:148篇
转载:24篇
评论:103条
(1)(6)(4)(5)(4)(6)(5)(6)(6)(6)(4)(8)(7)(6)(6)(6)(6)(7)(12)(7)(4)(7)(5)(4)(5)(3)(2)(4)(1)(1)(3)(1)(1)(2)(5)(1)(5)}

我要回帖

更多关于 禁止iframe跳出框架 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信