I have a problem in my javascript which is just to resize an iFrame based on the content. I have it working in other places but for this one example it is throwing an error. Using the following code the body is null and therefore can’t get scrollHeight.
if(document.getElementById('iFrameHelpDesk') != null)
{
var Height = document.getElementById('iFrameHelpDesk').contentWindow.document.body.scrollHeight;
document.getElementById('iFrameHelpDesk').height = Height + 40;
}
The html used is:
<iframe src="http://<snipped webaddress>" id="iFrameHelpDesk" scrolling="no" frameborder="no"></iframe>
Why does this not populate the body object?
Fairly simply I took the code from the document load (
$(function() {})) method and put it into it’s own method for when the actual iframe loads. Ie.This works perfectly, as it should. But it’s now confused me as to why some other iframes, which I perform similar code on, are working fine from within the document load. But this works and I’m happy enough with that.