想让iframe 出现这样一个效果:
在iframe的大小总是随着他内容的大小改变而改变。也就是说不要显示滚动条,但能把指定给他显示的网页全部显示,让他的父窗体的来出滚动条。
像<div></div>这样。不管它内容有多少总是能自动缩放。
用JS或CSS实现都行。

解决方案 »

  1.   

    <iframe id="iframe" onload="AutoIframeHeight(this)" src="ssssssssssss.aspx"/>function AutoIframeHeight(obj){
     var iframe=obj;
     if (document.getElementById){
      if (iframe && !window.opera){
       if (iframe.contentDocument && iframe.contentDocument.body.offsetHeight) 
        iframe.height = iframe.contentDocument.body.offsetHeight; 
       else if(iframe.Document && iframe.Document.body.scrollHeight)
        iframe.height = iframe.Document.body.scrollHeight;
      }
     }
    }
      

  2.   

    我的方法
    <iframe   src="test.asp"   width="100%"   frameborder="0"   scrolling="no"   name="hj"   id="hj"> </iframe> test.asp页面head间增加如下JS代码 <SCRIPT   LANGUAGE="JavaScript"> function   f_frameStyleResize(targObj){   var   targWin   =   targObj.parent.document.all[targObj.name];   if(targWin   !=   null)   {     var   HeightValue   =   targObj.document.body.scrollHeight     if(HeightValue   <   600){HeightValue   =   600}       targWin.style.pixelHeight   =   HeightValue;   } } function   f_iframeResize(){   bLoadComplete   =   true;   f_frameStyleResize(self); } var   bLoadComplete   =   false; window.onload   =   f_iframeResize; </SCRIPT> 
    具体见:http://topic.csdn.net/u/20080102/19/12636ed6-e4a8-4dfd-9b2f-dea9bdb5a271.html
      

  3.   

    我自己的一个方法:<script language="javascript">
        function AutoSize(IframeName)
        {
            var w=document.frames(IframeName).document.documentElement.scrollHeight;
        document.getElementById(IframeName).style.height=(w+10)+"px";
        }
        function Set()
        {
            setInterval("AutoSize('ShowFrame')",1000)
        }
        window.onload=Set;
        </script><iframe id="ShowFrame" name="ShowFrame" scrolling="no" frameborder="0" src="Index.htm"></iframe>