主要问题,写了一个iframe自适应高度的代码
  <iframe name="mainFrame" id="mainFrame" frameborder="0" marginheight="0" marginwidth="0"  src="main1.html" width="100%" height="500px" scrolling="no" onload="javascript:iframeOnload();" ></iframe>下面是iframeOnload()方法代码
function iframeOnload(){
  var o_iframe = document.getElementById("mainFrame"); 
  var bHeight = o_iframe.contentWindow.document.body.scrollHeight;
  var eHeight = o_iframe.contentWindow.document.documentElement.scrollHeight;
          o_iframe.height= Math.max(bHeight,eHeight);
       }在IE和360中没任何问题,在ff和chrome中,通常第一次载入的时候o_iframe.contentWindow.document.body.scrollHeight和o_iframe.contentWindow.document.documentElement.scrollHeight;,都能取得实际高度,但一旦刷新后,取得的高度要比实际高度大160px左右,如果不断刷新,又可能得到正确值,反正就是只要一刷新,取值就变得随意了,但始终要么取得正确值 ,要多比正确值高160左右!,找了半天,也不知道为什么,哪位知道的,帮忙解决下,小弟谢过了!

解决方案 »

  1.   

    搞定了,原来是交层方法执行慢过这个函数,哎,以后大家用到jquery里的slideup slidedown这些方法的时候一定要注意执行时间的问题
      

  2.   


    var thisHeight=$(document).height();
    var thisWidth=$(document).width();
    //iframe出了css的width还有width属性,因此把iframe的高度赋值给父级页面的iframe标签
    top.$("iframe[name='b']").height(thisHeight).attr("height",thisHeight)
    top.$("iframe[name='b']").width(thisWidth).attr("width",thisWidth);
    //在iframe的页面加载事件($(document).ready())和($(window).load())下面调用
      

  3.   


    var thisHeight=$(document).height();
    var thisWidth=$(document).width();
    //iframe出了css的width还有width属性,因此把iframe的高度赋值给父级页面的iframe标签
    top.$("#mainFrame").height(thisHeight).attr("height",thisHeight)
    top.$("#mainFrame").width(thisWidth).attr("width",thisWidth);
    //在iframe的页面加载事件($(document).ready())和($(window).load())下面调用
    //前面写错了