开发者

How to refresh iframe parent page after a submit in the iframe?

i have iframe inside a page, and this iframe contain a submit button which will do some function.

What i want is: after the iframe submit finish, call the parent page to refresh.

i know how to refresh it:

parent.location.reload();

But i don't know how to do that after submit开发者_如何学运维 finish.


Use an onload event handler on your iframe. When it fires after the submit, execute your top.location.reload...

// In parent
window.onload = function() {
  document.getElementById("MY_IFRAME").onload = function() {
    top.location.reload();
  }
}


I solved this problem by adding this line of code in the code behind after all my methods finished:

    ScriptManager.RegisterStartupScript(this, typeof(string), "script", 
"<script type=text/javascript>
parent.location.href = parent.location.href;</script>", false);

And the reason i didn't write parent.location.reload() and wrote parent.location.href = parent.location.href is to don't send the data twice to server as i want a new fresh page load.


Submitting a form is the FINAL action on the document in the Iframe. Once you submit a form, that page has been "submitted" and is no longer active. If you refresh the parent first, you lose the Iframe. The moment you submit in the Iframe, you can no longer talk to the parent.

You can do one of a few things here:

  • Target the PARENT when you submit the form, then the parent will have whatever you want in a NEW iframe on that page.
  • Have the resulting page in the iframe reload the parent using JavaScript on the result page.


If you only want to refresh some parts of the parent page and won't need to refresh the whole page, and most of the times this is the case since this approach doesn't reload the iframe itself, you can just call a javascript function from the child page.

window.parent.myFunctionInParent('my argument');

The resource that guides you is here: Refresh parent page partially from iframe

Thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜