Javascript jQuery更改iframe的大小

Javascript jQuery更改iframe的大小,javascript,jquery,html,iframe,Javascript,Jquery,Html,Iframe,我有一个函数,可以在每次加载新内容时更改iframe的大小 它工作正常,但有一个小问题: 如果我打开一个大的内容,大小会改变到正确的高度。如果在此之后加载较小的内容,则高度保持不变(从较大的内容开始),不会变短 我不知道为什么,我怎样才能修好它 $("#mainframe").load( function () { var c = (this.contentWindow || this.contentDocument); if (c.document) d = c.document;

我有一个函数,可以在每次加载新内容时更改iframe的大小

它工作正常,但有一个小问题:

如果我打开一个大的内容,大小会改变到正确的高度。如果在此之后加载较小的内容,则高度保持不变(从较大的内容开始),不会变短

我不知道为什么,我怎样才能修好它

$("#mainframe").load( function () {
  var c = (this.contentWindow || this.contentDocument);
  if (c.document) d = c.document;
  var ih = $(d).outerHeight() + 10;
  var iw = $(d).outerWidth();
  $(this).css({
    height: ih,
    width: iw
  });  
});

你能提供一把小提琴吗?看起来这个答案可能会有帮助:@problemPotato this not work:/and to keshu_vats,sry我的英语不是很好不知道你想说什么。