function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Resize IFrame?

Is it possible to resize an iframe within a VisualForce page? I have a script that would work, but the apex:iframe does not allow OnLoad()


<script language="JavaScript">


function autoResize(id){

    var newheight;

    var newwidth;



        newheight=document.getElementById(id).contentWindow.document .body.scrollHeight;

        newwidth=document.getElementById(id).contentWindow.document .body.scrollWidth;



    document.getElementById(id).height= (newheight) + "px";

    document.getElementById(id).width= (newwidth) + "px";





<IFRAME src=" " width="100%" height="200px" id="iframe1" marginheight="0" frameborder="0" onLoad="autoResize('iframe1');"></iframe>


Is this an iframe within a VF page, or are you attempting to resize a VF page embedded in a standard page?
OnDem DevOnDem Dev

Use Apex:Iframe tag with height and width values passed from Controller.

<apex:iframe src="...." height="{!frameHeight}" id="fId"/>

In Onload pass the values of height and width to controller and rerender the iframe once the onload gets finished.


Best regards

Message Edited by OnDem Dev on 01-13-2010 12:54 PM
Thanks for the tips, would you mind posting an example? I'm having some trouble getting it to work correctly.....
I seem to recall the onload doesn't work reliably if you are using standard headers in you VF page.
I cannot seem to get onload to work at all; any other suggestions???
Best advice I've seen on these boards is to add the call to the JavaScript to the end of your page if you can't use onload.  As long as the browser has rendered all the other components by that time it should work okay.
Right, that works only on rendered pages; I guess my situation is unique. There are three drop down menus where reports can be chosen to display >1 report per page. As the apex:iframe sections reload, that is when the resize function call needs to fire.
If you can get at the iframe objects using javascript, you should be able to add onload handlers to them.  Can you locate them via id?

I'm looking to do the same.  Were you able to get this working?




 I have tried  auto resizing of iframe but it did not worked if i use <apex:iframe> tag.


Is it possible by using that standard tag and not using simple html tag of <iframe> ??