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
ShiftAaronShiftAaron 

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;

 

    if(document.getElementById){

        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";

}

//-->

</script>

 

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

 

bob_buzzardbob_buzzard
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
ShiftAaronShiftAaron
Thanks for the tips, would you mind posting an example? I'm having some trouble getting it to work correctly.....
bob_buzzardbob_buzzard
I seem to recall the onload doesn't work reliably if you are using standard headers in you VF page.
ShiftAaronShiftAaron
I cannot seem to get onload to work at all; any other suggestions???
bob_buzzardbob_buzzard
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.
ShiftAaronShiftAaron
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.
bob_buzzardbob_buzzard
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?
ddarmondddarmond

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

QuriesQuries

Hi,

 

 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> ??