javascript 模态对话框关闭后如何刷新父页面?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22528233/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 23:18:33  来源:igfitidea点击:

How to refresh parent page after modal dialog is closed?

javascripthtmlasp.netmodal-dialog

提问by 3bdalla

I have an ASP.NET page that contains an tag which opens a modal dialog. This modal dialog contains a control that contains a button which saves some data and closes the modal dialog. How to refresh the parent page that button is clicked?

我有一个 ASP.NET 页面,其中包含一个打开模式对话框的标签。此模态对话框包含一个控件,该控件包含一个按钮,用于保存一些数据并关闭模态对话框。如何刷新点击按钮的父页面?

回答by Aristos

You can run this javascript line from the modal:

您可以从模态运行此 javascript 行:

window.top.location.reload();

or

或者

parent.location.reload();

If you do not have access to the modal, you can set a handler for the close as

如果您无权访问模态,则可以将关闭的处理程序设置为

ModalObject.onbeforeunload = function () {
  window.top.location.reload();
};

where ModalObject is the handler that you have when you creates it.

其中 ModalObject 是您在创建它时拥有的处理程序。