How to adjust IFrame height on it's content (转载)

http://www.codeproject.com/useritems/Adjust_An_iFrame_Height.asp

<iframe id='myFrame' frameborder=0 scrolling=no width=100%  src="..."
    <EM>onload='adjustMyFrameSize();'</EM>></STRONG> <STRONG>
</iframe>

Then you need to place such script BEFORE IFrame element: </P>

 <script type="text/javascript">
   
    function getElement(aID)
    {
        return (document.getElementById) ?
            document.getElementById(aID) : document.all[aID];
    }

    function getIFrameDocument(aID){
        var rv = null;
        var frame=getElement(aID);
        // if contentDocument exists, W3C compliant (e.g. Mozilla)
        if (frame.contentDocument)
            rv = frame.contentDocument;
        else // bad IE  ;)
            rv = document.frames[aID].document;
        return rv;
    }

    function adjustMyFrameHeight()
    {
        var frame = getElement("myFrame");
        var frameDoc = getIFrameDocument("myFrame");
        frame.height = frameDoc.body.offsetHeight;
    }
</script>

posted @ 2007-07-07 00:22  margiex  阅读(1059)  评论(0编辑  收藏  举报