I want to embede iframe in vf page. But my page height is not gettin set to height of iframe. so i tried following code but was not able to set height depending on iframe height.

<apex:page id="hompage" title="Homepage Visualforce" showheader="false"
sidebar="false" cache="false" standardStylesheets="false">
<apex:includeScript value="{!URLFOR($Resource.ShowCycleStaticResources,
'ShowCycleStaticResources/JQuery/jquery.min.js')}" />

<script type="text/javascript">
  $(window).load(function() {
     var parentIFrame = document.getElementById('homepageComponentiFrameId');
     alert("window load occurred!"+parentIFrame.contents().find("body").height() );

Can any body help to get

1 Answer 1


You can use the following piece of JavaScript to adjust the height of the iframe element to match the height of its content. You will get the full description in this link.

Iframe tag

<iframe src="iframe-content.html" frameborder="0" id="external-frame"></iframe>


     * When the iframe is on a different subdomain, uncomment the following line
     * and change "example.com" to your domain.
    // document.domain = "example.com";
    function setIframeHeight(iframe) {
        if (iframe) {
            var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
            if (iframeWin.document.body) {
                iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
    window.onload = function () {
  • not getting value in iframeWin. even alert('hi') message is not responding after var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow; Also I have set domain as given. Commented Oct 19, 2015 at 13:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .