This came up for me today and I wanted to share a solution for anyone else with this problem. This is a bit of a hack but as we all know working inside facebook is like that sometimes.
I have an application that lives in an iframe and inside that main iframe I have another iframe. I wanted to add a 'cancel' button to a fb request form that lives in that second iframe that would close a popup window that framed my request form (makes it look purty) that lives on the main iframe.
Here's what I did
<fb:serverfbml>
<script type="text/fbml">
<fb:fbml>
<fb:request-form action='<?=$callbackurl?>a_post.php?token=<?=$token?>' method='post' type='My App' content='<?=$content?>' invite='false' style="width:500px">
<input type='hidden' name='token' value='<?=$token?>' />
<fb:request-form-submit uid=<?=$uid?> />
<input type='button' class='inputbutton' name='cancel' value='Cancel' onclick='document.setLocation("<?=$callbackurl?>/callback_popup.php")'/>
</fb:request-form>
</fb:fbml>
</script>
</fb:serverfbml>
Then create callback_popup.php that has your javascript code in it, which now has the correct context to run. Define closePopup and you are set:
<script type="text/javascript">
<!--
parent.parent.closePopup();
-->
</script>