Jump to content

resize an iframe


Recommended Posts

Just now, Mylene said:

Hey everyone 

I wonder if someone has a solution for resizing an iframe depending on size of content.

I have an html datapage and need to deploy submission form in iframe and I'd like to avoid scrolling

Thanks!

I have a solution for your case. You may find code below:

<script>https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<script>
  function resizeIframe(obj) {
    obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
  }
</script>

<iframe  src="URL_of the datapage" frameBorder="0" scrolling="no" width=100% onload="resizeIframe(this)">Sorry, but your browser does not support frames.</iframe>

 

Don't forget to insert your URL instead of: URL_of the datapage

Link to comment
Share on other sites

  • 5 years later...
On 11/2/2017 at 12:53 PM, Mathilda said:

I have a solution for your case. You may find code below:

<script>https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<script>
  function resizeIframe(obj) {
    obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
  }
</script>

<iframe  src="URL_of the datapage" frameBorder="0" scrolling="no" width=100% onload="resizeIframe(this)">Sorry, but your browser does not support frames.</iframe>

 

Don't forget to insert your URL instead of: URL_of the datapage

Of all the solutions some are earlier than this one, this has helped me to resize the iframe according to its content and not reorder all the content in some way.

Thanks for the solution.

Link to comment
Share on other sites

  • 2 months later...

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