We have pages in our iframe that add content to the page and then allow the user to update the content on the page. In these cases, we saw the same where the content was not reduced when it was necessary.
FB.Canvas.setSize () calls _computeContentSize, which is shown below:
_computeContentSize: function() { var body = document.body, docElement = document.documentElement, right = 0, bottom = Math.max( Math.max(body.offsetHeight, body.scrollHeight) + body.offsetTop, Math.max(docElement.offsetHeight, docElement.scrollHeight) + docElement.offsetTop); if (body.offsetWidth < body.scrollWidth) { right = body.scrollWidth + body.offsetLeft; } else { FB.Array.forEach(body.childNodes, function(child) { var childRight = child.offsetWidth + child.offsetLeft; if (childRight > right) { right = childRight; } }); } if (docElement.clientLeft > 0) { right += (docElement.clientLeft * 2); } if (docElement.clientTop > 0) { bottom += (docElement.clientTop * 2); } return {height: bottom, width: right}; },
The problem line is here:
bottom = Math.max( Math.max(body.offsetHeight, body.scrollHeight) + body.offsetTop, Math.max(docElement.offsetHeight, docElement.scrollHeight) + docElement.offsetTop);
Even if the content inside your iframe has decreased, the value of body.offsetHeight will not decrease.
To solve this problem, we created a custom version of the computeContentSize function, which only processes docElement for height, for example:
function rfComputeContentSize() { var body = document.body, docElement = document.documentElement, right = 0, bottom = Math.max(docElement.offsetHeight, docElement.scrollHeight) + docElement.offsetTop; if (body.offsetWidth < body.scrollWidth) { right = body.scrollWidth + body.offsetLeft; } else { FB.Array.forEach(body.childNodes, function(child) { var childRight = child.offsetWidth + child.offsetLeft; if (childRight > right) { right = childRight; } }); } if (docElement.clientLeft > 0) { right += (docElement.clientLeft * 2); } if (docElement.clientTop > 0) { bottom += (docElement.clientTop * 2); } return {height: bottom, width: right}; }
At any time, when we want to resize and know that the content can be compressed, we will use a user-defined function to transfer the content to setSize (for example, FB.Canvas.setSize (rfComputeContentSize ())), and at any time we know that content will be only, we will use the standard function FB.Canvas.setSize ().
Please note that we used setAutoGrow (), and I did not check, but I assume that it uses the same function to determine the size. We have disabled our call to setAutoGrow () and will need to be vigilant about calling setSize () at the appropriate time.
Facebook bug recorded: https://developers.facebook.com/bugs/228704057203827