Posted By

Neven on 02/23/13


Tagged

iframe resize content


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

burnandbass
Abiotic
pedromagalhaes
Beppoi


Resize iFrame to its content


 / Published in: JavaScript
 

Bind onload function to the iFrame and set the size of the iFrame to the iFrames loaded content. In the example jQuery is used.

  1. $("#modalIFrame").bind('load',
  2. function () {
  3. var newheight,
  4. newwidth;
  5.  
  6. newheight = this.contentWindow.document.body.scrollHeight;
  7. newwidth = this.contentWindow.document.body.scrollWidth;
  8.  
  9. $(this).height(newheight);
  10. $(this).width(newwidth);
  11. }
  12. );
  13.  
  14. $("#modalIFrame").attr('src', url);

Report this snippet  

You need to login to post a comment.