Resize iFrame to its content


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments


You need to login to view comments.