javascript在提交时关闭弹出窗口

时间:2013-01-31 01:54:34

标签: javascript popup form-submit

确定。我已经看到这个问题已经有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年的相同解决方案,有些解决方案可以追溯到本月。我会继续看,但我希望有人钉了它,有人在这里回答

1 个答案:

答案 0 :(得分:6)

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

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

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

$("#myForm").ajaxForm(function() { 
    window.close();
})