0

When I click a button it opens up a popup window, there I submit some values which will be processed under a server side code. My problem is, I need to close this window from there, I tried all the possible answers from the stackoverflow. any suggestions are appreciated

Here is the below code, which I used in the server side

echo '<script>alert("Task closed successfully"); window.close(); 
header("location: dispclosedtask.php?key=".$followuptaskid);
Alon Eitan
  • 11,997
  • 8
  • 49
  • 58
kirupaji
  • 1
  • 4
  • 1
    Does this answer your question? [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Alon Eitan Nov 07 '20 at 14:33
  • The question would be better if PHP was removed as interactive content is client side (front end) and controlled by JavaScript, not PHP. If your button opens a form and you are submitting that form via PHP then you can refresh the page after submit and the popup will disappear without any need for JavaScript, unless you want to use the AJAX route? – SJacks Nov 07 '20 at 14:53
  • PHP runs on the server, it is not involved in any way in what happens in the browser (apart from generating the content that reaches the browser, but that is data for PHP, not PHP code). – axiac Nov 07 '20 at 14:56
  • hi every thing is working fine, but i need to refresh the page where I kept that button, this is where, I am struggling – kirupaji Nov 07 '20 at 15:38

3 Answers3

1

Get rid of all the PHP code you've shared. What you currently have is basically:

  1. JavaScript code to close current window:

     alert("Task closed successfully"); window.close();
    
  2. PHP code to load a different page before the browser has the chance of running prior JavaScript:

     header("location: dispclosedtask.php?key=".$followuptaskid);
    

Everything you need is:

<script>
alert("Task closed successfully");
window.close();
</script>
Álvaro González
  • 142,137
  • 41
  • 261
  • 360
0

after youre done submitting do this :

<?php    
    echo "<script>window.close();</script>";
?>
سعيد
  • 1,547
  • 1
  • 14
  • 32
0

I have completed this task successfully, thank you all for your sharings.

kirupaji
  • 1
  • 4