Javascript close popup

Ok I have seen this question unanswered for over 10 years.

How to send and close a popup with the click of a button.

proposals are implemented in this way.

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 no validation of the data.  it submits before the function is called.

Does anyone solve this? I found the same solutions as in 2002, and some are the last ones this month. I will continue to watch, but I hope someone nailed her and that someone answers here.

+5
source share
1 answer

A typical solution is to output a JS fragment that closes the window as the resulting page after sending.

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

Another solution would be to submit the form data via AJAX and close the window when the request is complete. You can use jQuery Form plugin to do this:

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

All Articles