简体   繁体   中英

Iframe height not adjusting with javascript in newer versions of Internet Explorer

I have an Iframe that links to another html page. The iframe is contained within a div. I found some code that would auto adjust the high depending on the contents of the iframe. This code works fine in firefox and older versions of internet explorer but its not adjusting the height in v7 or later.....

Javascript:

<script type="text/javascript"> 
    function changeContent(){ 
        document.getElementById('right').innerHTML = window.frames['contentFRAME'].document.getElementsByTagName('html')[0].innerHTML; 
    } 
</script>

HTML:

<div class="fl" id="right">
    <iframe class="newsFrame" id = "contentFRAME" name = "contentFRAME" src ="news.html" onLoad = "changeContent()"></iframe>
</div>

Can anyone help.....

Try this

function resizePanel() {
    window.console.log("ran the resize panel function");
    var frame = document.getElementsByTagName('iframe')[0];
    if(frame != null) {
        frame.style.height = frame.contentWindow.document.body.scrollHeight + "px";
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM