Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make an iframe resizable?

We have this group project and I was assigned to make a certain iframe resizable. I've been reading lots of forum posts since last week, and I found out that iframe itself can't be resizable.

Is there a way to make my iframe resizable?

like image 540
amielopez Avatar asked Nov 14 '11 05:11

amielopez


People also ask

How do I resize an iframe based on content?

The iframe HTML element is often used to insert contents from another source. Contents which needs resizing is done indirectly using a div tag. The trick is to initiate with a div tag and enclose within an iframe tag.

How do you expand an iframe in HTML?

Edit the width attribute. You should see the attribute "width=" after the URL in the iframe tag. Edit the width in pixels in quotations (" ") after the "width=" attribute. For example, if you want the width to be 300 pixels, you would enter "width="300px"" after the URL in the tag.

How can I resize my iframe height dynamically?

Answer: Use the contentWindow Property You can use the JavaScript contentWindow property to make an iFrame automatically adjust its height according to the contents inside it, so that no vertical scrollbar will appear.

Can iframes be made responsive?

The best trick for responsive iframes, for now, is making an aspect ratio box. First you need a parent element with relative positioning. The iframe is the child element inside it, which you apply absolute positioning to in order to fill the area.


Video Answer


2 Answers

This can be done in pure CSS, like so:

iframe {   height: 300px;   width: 300px;   resize: both;   overflow: auto; } 

Set the height and width to the minimum size you want, it only seems to grow, not shrink.

Live example: https://jsfiddle.net/xpeLja5t/

This technique has good support in all major browsers except IE.

like image 57
Nicole Sullivan Avatar answered Sep 28 '22 07:09

Nicole Sullivan


These steps will make an iframe resizable:

  1. Create a div for resizing. eg:

    <div class="resizable"></div> 
  2. Apply the style tag for style of div.

    .ui-resizable-helper {     border: 1px dotted gray; } .resizable {     display: block;     width: 400px;     height: 400px;     padding: 30px;     border: 2px solid gray;     overflow: hidden;     position: relative; } iframe {     width: 100%;     height: 100%; } 
  3. Include jQuery & jQuery UI

    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/start/jquery-ui.css"rel="stylesheet" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script> 
  4. Execute Resizable

    $(function () {     $(".resizable").resizable({         animate: true,         animateEasing: 'swing',         animateDuration: 500     }); }); 
like image 29
kuldeep raj Avatar answered Sep 28 '22 06:09

kuldeep raj