iframe自适应高度

<div id="leamain" style="width:500; height:auto;border:dotted 2px black;  ">

<a href="http://www.baidu.com" target="iframepage">baid</a>

<a href="http://www.sina.com" target="iframepage">sina</a>

 

       <iframe src="http://www.baidu.com" marginheight="0" marginwidth="0" frameborder="0" scrolling="no" width="300" height=100% id="iframepage" name="iframepage" onLoad="iFrameHeight()" ></iframe>

 

<script type="text/javascript" language="javascript">

 

    function iFrameHeight() {

 

        var ifm= document.getElementById("iframepage");

 

        var subWeb = document.frames ? document.frames["iframepage"].document :

 

ifm.contentDocument;

 

            if(ifm != null && subWeb != null) {

 

            ifm.height = subWeb.body.scrollHeight;

 

            }

 

    }

 

</script> 

 

     </div>

你可能感兴趣的:(iframe)