Jump to content

Resizing Iframes


Recommended Posts

Hi all,

 

I am looking for a working solution to resize iframe height and width.

 

I have used an iframe to embed a submission form on my website. This form has various rules  (4 in total) in place so as per option selected by the users , the form will change its height.

 

Ideally, I would like to resize the iframe accordingly. Will appreciate if somebody could share a successful solution they might have come across?

 

I have browsed a bit and found an interesting discussion thread on stack overflow . I tried various alternatives BUT with no success!

 

The code that I have currently embedded on the webpage is below,

------------------------

<head>
<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>
</head>
<body>
<iframe src="Caspio. URL of Datapage" width="100%" id="iframe1" marginheight="0" frameborder="0" onLoad="autoResize('iframe1');"></iframe></body>
----------------------
 
Any help most welcome!
 
Thanks in advance. K
 
 
 

 

 

Link to comment
Share on other sites

  • 5 months later...

Try this:



 

<iframe name="" id="iFrame1" title="02 Inline Providers_with FY choice" src="URL">Sorry, but your browser does not support frames.</iframe>


<script type="application/javascript">

function resizeIFrameToFitContent( iFrame ) {

    iFrame.width  = "100%";
    iFrame.height = "500px";
}


    var iFrame = document.getElementById( 'iFrame1' );
    resizeIFrameToFitContent( iFrame );

    // or, to resize all iframes:


</script>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...