Until recently we were using colorbox with divs, not iframes, as there was seemingly no way of resizing the iframe to match content. The knock-on effect of this was a whole heap of trouble trying to avoid postbacks of the overlay content as the parent page would postback too.
Using an iframe would make things so much easier technically as we could postback all we wanted in our overlay, opening up the opportunity for server-validation, pagination, file uploading etc, without posting back the parent page. And so it was that I looked into iframe resizing.
I achieved this using colorbox v1.3.9, and assume it works on later versions. Working code is available on my github here. In summary, drop this code into your jquery.colorbox.js file just before the publicMethod.resize function:
publicMethod.myResize = function (iW, iH) { if (!open) { return; } if (settings.scrolling) { return; } var speed = settings.transition === "none" ? 0 : settings.speed; $window.unbind('resize.' + prefix); settings.w = iW; settings.h = iH; $loaded.css({ width: settings.w, height: settings.h }); publicMethod.position(speed); };
And then in your iframe content page use the following:
jQuery(document).ready(function (){ jQuery(window).bind("load", function () { var frameWidth = jQuery(document).width(); var frameHeight = jQuery(document).height() + 20; parent.$.fn.colorbox.myResize(frameWidth, frameHeight); }); });This solution was adapted from a post found on the Google colorbox group.