You can get "scrollHeight" of the iframe's document's body. This represents the height of the contents of the iframe.
var content_height = frames["framename"].document.body.scrollHeight;
You can then set the height of the iframe element.
I made a basic working example you can test here:
It's been tested in ie7, 8, 9, and the latest firefox, opera, safari and chrome. I can't promise anything about other browsers.
If you want the resizing to happen automatically you can put it in the onload event of the iframe. I've just put it in an onclick event to illustrate the change.
I hope this helps and let me know if you have any questions.