Teach you to use jquery to implement iframe adaptive height


The iframe code, notice the ID

<iframe src="test.html" id="main" width="700" height="300" frameborder="0" scrolling="auto"></iframe>

Jquery code 1:

//Note: the following code is placed on the test.html call
$(window.parent.document).find("#main").load(function(){
var main = $(window.parent.document).find("#main");
var thisheight = $(document).height()+30;
main.height(thisheight);
});

Jquery code 2:

//Note: the following code is called on the same page as the iframe
$("#main").load(function(){
var mainheight = $(this).contents().find("body").height()+30;
$(this).height(mainheight);
});