`
keda413
  • 浏览: 20657 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

iframe 自适应高度 IE FireFox兼容

阅读更多
方法一:
function c()

{

var frm = document.getElementById("IframeId");
//document.frames["IframeName"].document获取子页面的document对象,可获得页面的各个对象,但是不能得到iframe标签的属性
document.getElementById("IframeUser")只是得到iframe标签对象,可获得标签的各个属性,但不能得到子页面的各个对象。document.frames为IE下使用,frm.contentDocument为firefox下使用。
var subWeb = document.frames ? document.frames["IframeUserName"].document : frm.contentDocument;

if(frm != null && subWeb != null)

{ frm.height = subWeb.body.scrollHeight;}

} 

方法二:
function d(){
 var frm=document.getElementById("IframeUser");
//frm.contentWindow.document为IE下 使用,获得子页面各个对象
var sub=frm.contentDocument ? frm.contentDocument:frm.contentWindow.document; 
 if(frm!=null&&sub!=null){
  frm.height=sub.body.scrollHeight;
 }
}

 

<iframe marginwidth=0 marginheight=0 src="2.html"   onload="d();" width="100%"    id="IframeId" name="IframeName"    frameborder="0"   scrolling="no"></iframe> 

 

 

分享到:
评论
1 楼 izat 2009-11-22  
多谢
找了一下发现大部分论坛的人貌似从来不用firefox的,给出的代码都只ie适用

相关推荐

Global site tag (gtag.js) - Google Analytics