You need to sign in to do that
Don't have an account?
Steven Fafel
IFrame dynamic height in view page
Hello all. We are looking to a solution for a height problem. We have an IFrame on a detail page (that contains a Visualforce page). The height of the content of the IFrame is dynamic but it seemed like our only choice was to set a fixed height on the IFrame. When the content doesn't fill the frame height, the result is a blank space. The image below (or attached) shows this blank space. Does anyone know how to set the height of the IFrame based on the height of the content?
<script>
// Resize the iframe that contains the Visualforce page
function resizeIframe() {
var frameHeight = document.body.scrollHeight;
var iframeElements = parent.document.getElementsByTagName("iframe");
for (var i = 0; i < iframeElements.length; i++){
if (iframeElements[i].title == '{!$CurrentPage.Name}'){
var iframeElement = parent.document.getElementById(iframeElements[i].id);
if (iframeElement) {
iframeElement.style.height = (frameHeight)+"px";
}
}
}
}
if (document.addEventListener) {
checkIfReady = function() {
document.removeEventListener("DOMContentLoaded", checkIfReady, false);
resizeIframe();
};
}
else if (document.attachEvent) {
checkIfReady = function() {
if (parent.document.readyState == "complete") {
parent.document.detachEvent("onreadystatechange", checkIfReady );
resizeIframe();
}
};
}
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", checkIfReady, false);
}
else if (document.attachEvent) {
parent.document.attachEvent("onreadystatechange", checkIfReady);
}
</script>
Does your suggestion really work? I get a cross site scripting error when I try it out:
Uncaught SecurityError: Blocked a frame with origin "https://c.cs87.visual.force.com" from accessing a frame with origin "https://cs87.salesforce.com"
Perhaps this workaround has been blocked in the Winter '16 release?
BR,
Peter