a.js
 document.write("<iframe id='floatDiv'  style='width:112px;padding-left:0px;' src='http://localhost:4905/Web/index.aspx?kfID="+kfID+"&style="+style+"&keyword="+keyword+"'"+"  frameBorder='0' width='100%' height='229px' scrolling='no' ></iframe>");如何让iframe自适应index.aspx的高度?

解决方案 »

  1.   

    try 
    onload="this.height=this.document.body.clientHeight"
      

  2.   

    height='229px' 改为height='100%',就可以自动伸展高度了~~
      

  3.   

    网页A里有一个frame叫F,F中有一个网页B,
    你可以在B页面中加一个方法,
    使B在加载完成后,执行这个方法:得到B的高度,通知parent也就是A,
    执行A中的JS,完成F的高度变化.
      

  4.   

    a.js 
    在其他网站的页面上,也就是别人的网页来调用我的a.js,不知这是不是跨域来操作
      

  5.   

    如果父页面与子iframe不在同一个域下,那基本不能实现iframe自适应.因为权限问题,很多属性取不到
      

  6.   

    给你我一直在用的代码function resizeIFrameHeight(){
    if(top.location != self.location){
    var frames = window.parent.document.getElementsByTagName('iframe');
    for (var i=0;i<frames.length;i++){
    if (frames[i].name == self.name){
    frames[i].height = document.body.scrollHeight;
    frames[i].width = document.body.scrollWidth;
    if(frames[i].name == "content"){
        if(frames[i].height<300)frames[i].height=300;
    }
    break;
    }
    }
    }
    }
    resizeIFrameHeight();将这个代码放在作为iframe的页面的最后,不要放在head部分,不存在跨不跨域的问题,在IE和FF中工作正常,没有试过其他的浏览器
      

  7.   

    解决了,谢谢各位,我这个不是跨域问题,因为a.js与index.aspx是同一个网站下的
    解决问题办法:index.aspx加
    <body onload="parent.document.getElementById('floatDiv').height=document.getElementById('div_kf_Float').scrollHeight;;">
    我这种情况并不适合所有情形,我的情形是index.aspx最外层'div_kf_Float'层,而且它的高试也是随里面的内容不同高低将不同。scrollHeight这个属性很多解决此问题
      

  8.   

    最外层'div_kf_Float'层不要设置高度样式,这样它会随内容的高度而自动调整
      

  9.   

    window.parent.document.getElementById('floatDiv').style.width=document.documentElement.clientWidth;
    或者
    width:expression(document.documentElement.clientWidth>600?"600":auto)