例如我在我的网站中嵌套一个其他网页,例如http://www.sohu.com,iframe的高度如何自适应?

解决方案 »

  1.   

    给 iframe 加个 onload 事件,设置高度就写在onload事件里。
      

  2.   


    现在就是不知道怎么得到iframe里那个网页的高度。
      

  3.   

    function pageWidth(){
     return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
    }
    function pageHeight(){
     return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
    }在你的子窗体中调用以上两个函数获取内容宽度跟高度,然后传给主窗口,在主窗口中设置iframe的宽度跟高度,前提是子窗体是你自己的,具有完全的控制权,否则也没啥好办法了 ~~
      

  4.   


     var doc;
    if (! +"\v1") //IE
       doc = document.frames["frame1"].document;
    else
       doc = document.getElementById("frame1").contentDocument;
    $('#frame1').height(doc.body.scrollHeight);
      

  5.   

    跨域的iframe不能实现自适应高度的。除非2个域名都是自己的并且可以修改里面的代码