Auto iframe height doesn't work when changing page in IE

I have an iframe on the page with the following auto-height script.

function autoHeight(e)
{
    if ( e.contentDocument ) {
        e.height = e.contentDocument.body.offsetHeight + 35;
    }
    else {
        e.height = e.contentWindow.document.body.scrollHeight + 35;
    }
}

document.domain = "example.co.uk";
var ifr = document.getElementById('housingdata');

ifr.onload = function() {
    autoHeight(ifr);
}

the iframe resizes when the external page loads, but when I go to a new page in the iframe, scroll bars appear and the page does not change in Internet Explorer. In other browsers, the iframe changes because the onload event fires every time.

I use IE8, but the external page sets it to IE7 compatibility mode. Is there a way around IE?

+3
source share
2 answers

. script script ( autoHeight) iframe:

window.onload = function() {
    var ifr = window.parent.document.getElementById('housingdata');
    autoHeight(ifr);
}

, , , iframe .

+1

onload="autoHeight(this)" iframe -tag ( , , , ... , , , )? , script, ... , -

0

Source: https://habr.com/ru/post/1741071/


All Articles