在 Sharepoint 表单中添加附件时,使用 addEventListener beforeunload 保存事件不会触发

Save event with an addEventListener beforeunload not firing when add attachments in Sharepoint form

我正在使用 IE11、JavaScript 和 SharePoint 2013。有一个主页可以打开一个新的表单选项卡 (NewForm.aspx) 来添加或编辑选项卡表单 (EditForm.aspx) 编辑记录。

当用户在新表单选项卡中保存时,它会保存数据、刷新主页并关闭新表单选项卡。

当用户在编辑表单选项卡中保存时,它会保存数据、刷新主页、刷新编辑表单选项卡并停留在该编辑表单选项卡记录上。

这适用于下面提供的代码,除非用户通过 SP 功能区中的“附加文件”按钮附加文件。它进入保存点击事件,点击 window.addEventListener,然后跳过它。用户默认回到 SP 库 AllItems.aspx 列表。

我试过将代码放在“保存”点击中,而不是放在 beforeunload 事件侦听器中,但是附件没有保存到项目中。

我已经尝试捕获文件附加事件 ($('input[id=attachOKbutton]')) 并添加一个 beforeunload 侦听器。

同样,问题是保存记录并停留在“编辑表单”选项卡上,即使用户附加了文件也是如此。

$(function() {
  $('input[value=Save]').click(function() {
    window.addEventListener("beforeunload", function(event) {  //does not go in here if file is attached
        var idxForm = location.pathname.indexOf("NewForm.aspx");
        if( idxForm >= 0 ) {  //NewForm - Saving a new record
            window.opener.location.reload(); //Refresh calling page
            window.close();
        }
        var idxForm2 = location.pathname.indexOf("EditForm.aspx")
        if( idxForm2 >= 0 ) {  //EditForm - Saving an update to a existing record
            window.opener.location.reload(); //Refresh calling page
            history.go(-1);
            location.reload(true);
        }   
    });
   });
});

实际结果:记录保存了附件,用户被定向到 SP 库 AllItems.aspx 或者用户停留在 EditForm.aspx 选项卡上,但记录未使用添加的附件更新。

Desired/Expected 结果:执行与用户保存而不添加附件时的操作完全相同...调用页面更新,编辑页面更新,用户停留在编辑页面。这也需要在用户添加附件时发生。

最终使用 EditForm url 在保存事件上设置会话 cookie,并在 AllItems.aspx 中对其进行测试,因此如果为真,它将重定向回特定的编辑记录页面。