0

Does anyone know of a way to auto resize an iframe when you make your browser smaller??

user1177860
  • 509
  • 4
  • 12
  • 24
  • possible duplicate of [How to resize iframe when parent window resizes](http://stackoverflow.com/questions/6634582/how-to-resize-iframe-when-parent-window-resizes) – MK. Feb 24 '12 at 14:07
  • check this it is the best preview sample http://stackoverflow.com/questions/10845452/how-to-render-a-full-webpage-in-smaller-iframe – Joseph Aguilar Aug 06 '13 at 09:53

5 Answers5

1

You can attach a handler to the window.onresize event, and then resize your IFRAME appropriately.

I prefer jQuery:

$(window).resize(function() {
  $('IFRAME').width($(window).width());

});
moribvndvs
  • 42,191
  • 11
  • 135
  • 149
0

One option is to specify the <iframe> size in percent.

Alexander Pavlov
  • 31,598
  • 5
  • 67
  • 93
0

Haven't tried it but I guess you could use a percentage width instead of a fixed width. In that case you should probably add a minimum width and height as well, to avoid that it is getting too small:

iframe
{
   width: 50%;
   height: 50%;
   min-width: 300px;
   min-height: 300px;
}
Christofer Eliasson
  • 32,939
  • 7
  • 74
  • 103
0

You could as well use this.

Basically it makes use of callResize() in Child page and resizeIframe() in Parent page.

Frankline
  • 40,277
  • 8
  • 44
  • 75
0

You can also do this without JavaScript if you'd like using CSS Media Queries. See this example here:

http://ie.microsoft.com/testdrive/HTML5/CSS3MediaQueries/Default.html

They are often used for "responsive design".

pseudosavant
  • 7,056
  • 2
  • 36
  • 41