How do ensure that the redirect doesn happen until after the form data has been posted?
You can trigger the redirect from the frame’s onload handler. Depending on how your code is written, this onload handler may get called twice — once when the page initially loads and once when the form is submitted. If this is the case, you’ll have to make sure that you change document.location on the second time only.