View Full Version : help: How to auto close pop up when finished.

10-12-2003, 10:36 AM
We want to have it so when a HTML form is submitted (a person is uploading a picture) that a Javascript will open a pop up window and then automatically close the window once the file is sent sucessfully.

See, we use like it's w = window.open(blah blah to open and w.close() to close but when the form is submitted w gets destroyed, so we need a way to close it without w or pass w to the next page or need a way for the popup to check when form is done submitting so it can close itself

Does anyone know a good way to do this?


10-12-2003, 12:55 PM
I think that this is in the wrong forum - havent i seen this post some where else too?

10-12-2003, 12:56 PM
you could use the tineout function to do that.

10-12-2003, 04:21 PM
You could have an onsubmit handler like this:

<form ....onsubmit="openwin(location.href); return true;">

...with the openwin() function along the lines of this:

function openwin(loc) {
var x = window.open();
x.document.write("Please wait, processing.....");

setInterval(function() { if(opener.location.href != loc) x.window.close(); }, 100);

I *think* that will work.

Hope that helps!

Happy coding! :)

10-13-2003, 10:52 AM
put this in the page after form submission:

<script type="text/javascript">
var popup = window.open("","nameOfPopup");
if (popup && !popup.closed) popup.close();

That will do the trick. Just specify the same target name used in opening the popup in the previous page.