用子页面(js)刷新父页面

今天在做系统的时候,在做添加新闻模块的时候。用到了添加完新闻后要刷新父页面来更新数据,所以就在网上找了些资料~解决了问题~

js刷新父页面

非模态刷新父页面:window.opener.location.reload();
模态刷新父页面:window.dialogArguments.location.reload();

Response.Write("<script language=\"javascript\">\r\n");
Response.Write("<!--\r\n");
Response.Write("if(dialogArguments != null){\r\n");
// 注意上面的dialogArguments,就是父页面showModalDialog()的第二个参数。
// 就是父页面的window对象引用。
Response.Write("dialogArguments.location.reload(true);\r\n");
// 上面就是刷新父页的代码,相当于在父页上使用
// window.location.reload(true);代码
Response.Write("window.close();}"); // 关闭对话框
Response.Write("//-->\r\n</script>"); //关闭脚本块
}
上面的代码就是关闭对话框和刷新父页的代码,这段代码也可以直接写入editdata.aspx的html中,然后在后台cs中调用

 



原文地址:https://www.cnblogs.com/astar/p/862277.html