Skip to content

Instantly share code, notes, and snippets.

@datchley
Created October 2, 2013 13:06
Show Gist options
  • Select an option

  • Save datchley/6793419 to your computer and use it in GitHub Desktop.

Select an option

Save datchley/6793419 to your computer and use it in GitHub Desktop.
An attempt to set each iframe's width/height on the page to the width/height of it's contained document.
$('document').ready(function() {
$('iframe').load(function() {
'use strict';
var self = this;
setTimeout(function() {
var iframe = self,
w = $(iframe).width(), h = $(iframe).height(),
docw = iframe.contentWindow.document.width,
doch = iframe.contentWindow.document.height;
console.log("resizing " + w + "x" + h + " to " + docw + "x" + doch);
(docw > w) && $(iframe).width(docw);
(doch > h) && $(iframe).height(doch);
}, 50);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment