Could someone tell me how to make an iframe resize based on the content without having to refresh the parent frame.

I have found some things that require java script in the frame document however i'm not sure how to integrate this, as the document my iframe links to is php not html.

I control both sides, parent and framed documents, so i just need to know what script to put where. Does anyone know how to do this?

Thanks

Hi,

I didn't really know what you ment by this question so I have answered the two possibility's to the best of my knowledge.

You could just add PHP tags into your IFrame tag:

<iframe frameborder="0" scrolling="no" height="<?php print($Hight); ?>" width="<?php print($Width); ?>" src="/page.php" />

And add in some variables earlier in the page.

If you wanted to resize the IFrame from inside It I don't think you could do that.

Regards,
Sam Rudge

On second thoughts I think there might be a way but it might be tricky.

If you used $_SESSION variables you could probably do it but you would have to reload the main page.

On the main page insert this PHP along with the IFrame HTML:

<?php
session_start();
if ( !isset($_SESSION["Resize"]) ) {
/* This is what happens the first time the person visits the page */
$Hight = "100px";
$Width = "120px";
} else {
/* This is if the Session has been set */
$Hight = "20px";
$Width = "50px";
};
?>

<iframe frameborder="1" scrolling="no" height="<?php print($Hight); ?>" width="<?php print($Width); ?>" src="/page.php" />

Then on page.php (The page requested in the IFrame) put in this code:

<?php
session_start();
$_SESSION["Resize"] = "1";
?>
<a href="/page_with_iframe_on.php" target="_top">Some Link</a>

When the user clicks on the link there main browser will be sent to the same page but the $_SESSION variable 'Resize' would be set so it would use the second set of dimensions.

Regards,
Sam Rudge

P.S. You would probably get more help if you posted this in the PHP forum on this site.

Thanks a lot Sam.
The second is sort of what I was thinking, I'll give it a try. If it doesn't work I try posting in the PHP section.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.