Alex Neigher
Alex Neigher

Reputation: 907

Can Javascript close a window when a file finishes uploading to a server?

Currently I am making a POST to our server, and I would like to be able to close the window.open popup after the file finishes uploading. Right now, I am using:

setTimeout(function()
 {
   imageUploadWindow.close();
 }, 5000);

However, this introduces a timing bug with varying file sizes or internet connections that I would like to avoid. Anyone know of a method by which I can have the window close after a 100% upload?

Upvotes: 1

Views: 565

Answers (2)

Anubhav Ranjan
Anubhav Ranjan

Reputation: 1598

You can have your server respond back with some result which signifies that upload is done. Once you receive the response from the server, you can then check the result and perform any operation you want. Say your server responds back saying "upload_completed". On this result, you can fire the JavaScript code to close the window.

Upvotes: 0

Jeow Li Huan
Jeow Li Huan

Reputation: 3796

After the POST, have your server redirect the browser to a page with the script that closes the window.

Upvotes: 2

Related Questions