0

I want to show a remote url's content or site in popup using iframe. But i do not want to fix height of iframe. I have already used some code

function resizeIframe(iframe) {
  iframe.height = iframe.contentWindow.document.body.scrollHeight + "px";
}

for

and i have tried another code

document.getElementById('iframe1').scrollHeight();

But this is not working. Please suggest

smart developer
  • 224
  • 2
  • 14

2 Answers2

1

Try this:

newheight = document.getElementById(iframe1).contentWindow.document.body.scrollHeight;
//For Firefox:
document.getElementById(id).height = (newheight) + "px";

//For Other:
 $('#' + iframe1).css('min-height', newheight + 'px');
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125
  • var newheight = document.getElementById('iframe1').contentWindow.document.body.scrollHeight; alert(newheight); but its not working – smart developer Jan 20 '14 at 10:35
1

I think you missed style attribute:

iframe.style.height = iframe.contentWindow.document.body.scrollHeight + "px";

Or for the second I think you should do something like

$('#iframe1').height(300); //will set your Iframe height with id iframe1 to 300px

Otherwise

$('#iframe1').css("height", "300px") //do the same

Morrisda
  • 1,380
  • 1
  • 11
  • 25
  • Remember to include jQuery in your pages if you use the second or the third solution ! – Morrisda Jan 20 '14 at 10:02
  • var newheight = iframe.contentWindow.document.body.scrollHeight; alert(newheight); but its not working – smart developer Jan 20 '14 at 10:35
  • Newheight = Iframe.contentWindow.document.body.offsetHeight + 'px'; Try it. Now I can't test, I am from mobile sorry. @devjohn – Morrisda Jan 20 '14 at 10:38
  • Sorry for wrong uppercase in my previous comment, correct them before testing. It's mobile's corrector fault – Morrisda Jan 20 '14 at 10:44
  • Have a look here, seem to be solved: http://stackoverflow.com/questions/3846132/jquery-get-height-of-iframe-content-when-loaded @devjohn – Morrisda Jan 20 '14 at 11:14