Skip to content

Instantly share code, notes, and snippets.

@longlostnick
Created January 31, 2012 20:08
Show Gist options
  • Save longlostnick/1712614 to your computer and use it in GitHub Desktop.
Save longlostnick/1712614 to your computer and use it in GitHub Desktop.
Cross browser iframe scrollWidth/scrollHeight and resize iframe to content
// Works for me in IE7+, Webkit, and FF
function resizeToContent(frame_id) {
var my_frame = document.getElementById(frame_id);
var content_width = my_frame.contentWindow.document.documentElement.scrollWidth;
var content_height = my_frame.contentWindow.document.documentElement.scrollHeight;
my_frame.style.width = content_width + 'px';
my_frame.style.height = content_height + 'px';
}
Copy link

ghost commented Sep 12, 2016

Thank you!

Finally found the solution for my problem! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment