5

行。我已经看到这个问题超过 10 年没有答案了。

您如何在一个按钮调用中提交和关闭弹出窗口。

建议就这样运行。

function saveNClose()
{
  document.form.submit();
  self.close();
}
this doesn't work because the submit has a redirect, and the self.close is never reached.

function closeLaterNSaveNow();
{
  setTimeout("window.close()",5000);
  document.form.submit();
}
same problem..  the close is never called because the script for the page is gone.

function closeNowNSubmit()
{
  self.close(); 
 document.form.submit();
}
the window closes, but nothing gets saved.  server doesn't even get notified of anything..

<input class='btn btn-success' disabled='disabled' id='SubmitFinal' onclick='closeWindow()' type='submit' value='Finish'>
Well then there's no validation of the data.  it submits before the function is called.

有人解决这个问题吗?我找到了可以追溯到 2002 年的相同解决方案,其中一些最近在本月。我会继续看,但我希望有人已经确定了,并且有人在这里回答

4

1 回答 1

6

一个典型的解决方案是输出一个 JS 片段,该片段将在提交后作为结果页面关闭窗口。

<script type="text/javascript">
    window.close();
</script>

另一种解决方案是通过 AJAX 提交表单的数据,并在请求完成后关闭窗口。您可以为此使用jQuery Form 插件

$("#myForm").ajaxForm(function() { 
    window.close();
})
于 2013-01-31T02:39:07.370 回答