If you have ever tried to perform an action within an iFrame when a window is resized then you would notice that using the “onresize” event of the body element within the iFrame is useless. For some reason, the “onresize” event of the page within the iFrame does not fire when the window itself is resized, so attaching a “onresize” event to the body tag of the page doesn’t work.

So basically this is the structure of your page:


<html>
<head></head>
<body>

<iframe id="myIframe" src="iframepage.html"></iframe>

</body>
</html>

Now you want to capture the “onresize” event of the window in your iframe so you can manipulate your interface or do something when it occurs. On a regular page (which has no iframes), placing this in your ‘body’ tag would help.

However, in your iFrame page, using the following will allow you to capture the ‘onresize’ event.

<script>
self.parent.window.attachEvent(”onresize”, myFunction);
</script>

Place the script tag on your page and it will attach the function to the event.

Leave a Reply