how to close popups with javascript

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
t-cat
Forum Newbie
Posts: 12
Joined: Fri Apr 07, 2006 5:40 am
Location: South Africa

how to close popups with javascript

Post 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?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Moved to client side
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

When the download completes, you could redirect to a new page that would close the popup window. document.close() or something =/
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
t-cat
Forum Newbie
Posts: 12
Joined: Fri Apr 07, 2006 5:40 am
Location: South Africa

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
t-cat
Forum Newbie
Posts: 12
Joined: Fri Apr 07, 2006 5:40 am
Location: South Africa

Post by t-cat »

Brilliant!

I bow down to your superior knowledge!!

The first one worked perfectly.

Thanks a lot :D
Post Reply