Page 1 of 1

how to close popups with javascript

Posted: Wed Apr 12, 2006 2:34 am
by t-cat
This one is a bit tricky:

I have a web page that allows the user to upload a file to the web server. The files in question can get fairly large for web uploads.

I want to create a popup when the page is submitted that tells the user to please wait. (easy enough)

This popup needs to be closed once the upload is complete. Here's the tricky part. Because the popup was loaded on submit, the javascript loses the handle to the popup once the page reloads, preventing it from closing through the handle.

Any thoughts on how to get around this?

Posted: Wed Apr 12, 2006 5:08 am
by JayBird
Moved to client side

Posted: Wed Apr 12, 2006 6:14 am
by s.dot
When the download completes, you could redirect to a new page that would close the popup window. document.close() or something =/

Posted: Wed Apr 12, 2006 7:11 am
by t-cat
My problem is that once the form has been submitted, the handle to the popup is lost.

This closes the popup, but the form is not submitted:

Code: Select all

<script type="text/javascript">
function opennotify()
{
	nw=window.open('waiting.php','waiting','height=100,width=300');
}
function closenotify()
{
	nw.close();
}
</script>


</head>

<body>

<input type="submit" name="submit_o" value="Open" onclick="javascript:null(opennotify())" />
<input type="submit" name="submit_c" value="Close" onclick="javascript:null(closenotify())" />

</body>
This submits the form, but can't close the popup:

Code: Select all

<script type="text/javascript">
function opennotify()
{
	nw=window.open('waiting.php','waiting','height=100,width=300');
}
function closenotify()
{
	nw.close();
}
</script>


</head>

<body>
<form enctype="multipart/form-data" method="post" action="index.php">
<input type="submit" name="submit_o" value="Open" onclick="javascript:null(opennotify())" />
<input type="submit" name="submit_c" value="Close" onclick="javascript:null(closenotify())" />
</form>
</body>
I need the best of both worlds

Posted: Wed Apr 12, 2006 10:03 am
by pickle
What about opening a window with the same name on the 2nd page, then closing it?

Page1

Code: Select all

window.open('myPage.php','specificName');
Page2

Code: Select all

blankWindow = window.open('blank.php','specificName');
blankWindow.close();

If that doesn't work (though it should), try getting the popup window to close itself. Throw a function in that window that checks it's parent window every 250 ms or so for a particular element. If that element exists, close the window.

Posted: Thu Apr 13, 2006 2:23 am
by t-cat
Brilliant!

I bow down to your superior knowledge!!

The first one worked perfectly.

Thanks a lot :D