Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resize a iframe inside the containing page?

I want to access the iframe my page is in and resize it. By the way I'm doing it in javascript.

It's something like parent and height or offsetHeight.

<iframe src="mypage.asp" height="400" width="400" ></iframe> 

And in mypage.asp I do sth similar like this:

var h = // new height;
parent.height = h; 

But it ain't all right? Somebody else who knows more?

like image 815
poo Avatar asked Mar 24 '10 09:03

poo


People also ask

How do I resize an iframe in HTML?

Edit the width attribute. You should see the attribute "width=" after the URL in the iframe tag. Edit the width in pixels in quotations (" ") after the "width=" attribute. For example, if you want the width to be 300 pixels, you would enter "width="300px"" after the URL in the tag.

How do I fit an iframe to my website?

Create HTML Create a <div> element with an id "wrap". Place an <iframe> element with an id "scaled-frame" inside the <div>. Add the src attribute with the content you want to display.


1 Answers

Try this if you want to resize the iframe from within the page that is loaded in your iframe. It seems to work locally at least:

function doIt() {
    var elem = window.parent.document.getElementById('myIframe'); // the id of your iframe of course
    elem.style.height = '40em';
}

I assume both the page and your iframe are yours and have the same "origin".

like image 50
npup Avatar answered Nov 03 '22 13:11

npup