Teach you to use jquery to implement iframe adaptive height

  • 2020-03-30 03:19:02
  • OfStack

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
var main = $(window.parent.document).find("#main"); 
var thisheight = $(document).height()+30; 

Jquery code 2:

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

Related articles: