1

I have this code:

<iframe id='iFrame' src='iframe.php' onload='javascript:iFrameResize(this);'></iframe>
function iFrameResize(obj) 
{
    obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
}

It works fine when I first load the page. But, when I select something in the iframe and the content height is larger than the iframe height, the iframe does not resized.

Is there a way to always resize the iframe when it's content changes(the iframe location does not change, content is added/modified with javascript)?

Thanks in advance.

4
  • 1) onload triggers on load and not on click of something 2) javascript: pseudo protocol/label is unnecessary
    – mplungjan
    Dec 18, 2012 at 10:29
  • I know that, i need a way to resize the iframe on content update without reloading the src url. Dec 18, 2012 at 10:42
  • 1
    Are the frame and the top document in the same domain (thus "accessible" via JS in either direction)?
    – Passerby
    Dec 18, 2012 at 11:11
  • yes, they are on the same domain. Dec 18, 2012 at 11:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.