«

»

Nov 15 2011

Resizing iframe from content

When you want to give both your advertisers and your users the best experience, you sometimes want to resize an iframe (and maybe also a surrounding div) from within the iframe’s content.

For instance – if you’ve booked a 728×90 in a 930×180 container, you might want to collapse the ad space to half of the original height.

The solution is simple – add this to your ad code

<script language="javascript">
if (window.frameElement) window.frameElement.style.height = "90px";
// if you also have a surrounding div:
if (window.frameElement.parentElement) window.frameElement.parentElement.style.height = "90px";
</script>

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>