如何在javascript中关闭弹出窗口后刷新父页面?

我有一个页面list.jsp ,其中list.jsp表格中所有记录的列表,以及一个用于添加新记录的按钮。

我想打开add.jsp作为弹出窗口。 这工作,但当我关闭弹出窗口时,如何更新list.jsp以便它显示新添加的记录

这是我的代码,我试过…

  1. 的List.jsp

        function popupwindow(url, title, w, h) { var left = (screen.width/2)-(w/2); var top = (screen.height/2)-(h/2); popupWindow = window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left); return popupWindow }      // Here i am showing all records from database... 
  2. add.jsp

         $(document).ready(function(){ $("#savebtn").click(function(e) { $.ajax({ type: "POST", url: "RecordHandler", data: dataString, success: function(data){ $('body').html(data); $('#msg').html('New Record Added Successfully.') } }); });   
    Folder Number
    Box Number *

从我对其他答案的评论中你只需要处理window.onunload事件并使用window.opener属性来告诉刷新调用页面。

2.add.jsp

    

您可以使用location.reload(true)重新加载当前文档。 forceGet参数默认为false ,这就是您将其作为true传递以覆盖它的原因。 基本上它用于从服务器获取文档,而不是从缓存中加载它。

编辑1:如果您尝试重新加载弹出窗口的源窗口,如注释中提到的escaparello,则应调用window.opener.location.reload() 。 此外,您可以在弹出窗口卸载时绑定事件侦听器,如下所示:

 popupWindow.onunload = function () { // This informs the user that the record has been added successfully alert('The record has been inserted into the database!'); window.opener.location.reload(); }