Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close Popup when new page loads

Status
Not open for further replies.

walderr

Programmer
Jul 18, 2003
32
GB
I've got a form for uploading documents made using asp. As it takes a while to upload many documents, I've added a popup window with an animated gif which comes up on submitting the form, so that the user knows something is actually happening. That's all fine so far.

Next, I need to close the popup when either the next page fully loads, or when the next page redirects back to the form with an error message (which is already built in to ensure that no fields are left blank). In the latter case, it would be preferable not to even open the popup, as no document is actually uploading, but I thought I'd start simple!
 
onpnt has written a FAQ for this...

for the first question ie redirection if theere is an error u dont even have to worry cause the page must be redirected before any html is outputted.
for the second one i have a doubt. how and in which page do u open the popup page?

Known is handfull, Unknown is worldfull
 
Basically, there are 3 pages:
1)The data input form
2)The popup which should appear while the document is uploading
3)The confirmation page which actually has the upload script in it - although it doesn't show until the upload has finished running

On submitting the form, the popup opens and the asp variables are sent to the confirmation for which starts uploading them.
 
the concept is simple:
1. write a javascript function to open the popup page.
2. write the asp code after the js function.
3. after the asp code write another JS function that closes the popup window...

am i clear?

Known is handfull, Unknown is worldfull
 
OK, I've done very little JS, and I've only just started asp as well, so this is all a little new to me...
I've got the function to open the popup (on page 1, carried out as an 'onclick' function)

The asp is on the next page, which currently has no JS

And I'm not sure how to get the popup to close, other than closing it from within itself.

That make sense?!! Sorry to be a pain!
 
take the code from page 1 to page 2. do something like this in page2:
<body>
<script>
//code to open window (dont use the function name simply type window.open....
wn=window.open('animate.html')
</script>
<%
'asp ulpoad code here
%>
<script>
win.close()
</script>

does this make sense now?

Known is handfull, Unknown is worldfull
 
Been there, tried that I'm afraid! Even though the JS is above the asp in the code, it doesn't open the window until it has finished uploading the document and opened the confirmation window... at which point it is a bit pointless having it! I think this one might be a bit more complicated than it seemed at first!
 
well now u have me. try reading the FAQ in the ASP forum. its by onpnt. the situation is the same... i will also try to dig some info...

Known is handfull, Unknown is worldfull
 
Hi -- I'm trying to do the exact same thing. I have some demo pages.

test1.htm
---------------------
<script language=&quot;JavaScript&quot;>
function openWin() {
var newwin = window.open(&quot;test2.htm&quot;, &quot;newwin&quot;);
newwin.focus();

document.location.href=&quot;test3.htm&quot;;
}
</script>

<a href=&quot;javascript:eek:penWin();&quot;>open window</a>


test3.htm
---------------------
<script language=&quot;JavaScript&quot;>
newwin.close();
</script>

Test 3



test2.htm is just some text. The popup window loads but then when I try to call to it from test3.htm it won't do anything with the window.

HELP?!
 
Can you fake it?

Have an onLoad setTimeout that closes the nw window,

Here's an example:
Code:
<html><head><title>New</title>
<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>
function nwwin() {
popwidth=400;
popheight=450;
leftpos1=120;
toppos=110;
popbackground=&quot;orange&quot;;
textdescription=&quot;TEXT HERE&quot;;
var winattributes='width='+popwidth+',height='+popheight+
 ',scrollbars=yes,resizable=yes,left='+leftpos1+',top='+toppos;
var bodyattribute= 'bgcolor=\&quot;'+popbackground+'\&quot;';
jkpopwin=window.open(&quot;&quot;,&quot;win3&quot;,winattributes)
jkpopwin.document.write(&quot;<html><title>test</title><head>\n&quot;+
  &quot;<script language='Javascript'>\n function cls()\n \{self\.close()\}\n&quot;+
  &quot;<\/script><head>\n<body &quot;+bodyattribute+
  &quot; onLoad=\&quot;setTimeout(\'self.close()\',4000)\&quot;><center>\n<br>&quot;+
  &quot;<br><table width=\&quot;700\&quot;><tr>\n<td>&quot;+textdescription+&quot;</td><td>&quot;+
  &quot;<b>New Win Atttrib's Are: &quot;+winattributes+&quot;</tr></table>\n<BR><BR>&quot;+
  &quot;<BUTTON onClick='cls()'>Close Window</BUTTON>&quot;+
  &quot;</center></body></html>&quot;);
jkpopwin.document.close();
jkpopwin.focus();}
</script></head><body>
<a href=&quot;test3.htm&quot; onClick=&quot;javascript:nwwin();&quot;>
New Window</a>
</body></html>


2b||!2b
 
Yeah I thought about doing that but the page time could be anywhere from instant (not really even needing the &quot;please wait&quot; window) to a minute or so on a slow connection.

I also tried a script I found here where I set the opener URL in a variable on the popup window, then repeatedly checked for the opener. When I didn't find it then I closed the popup. That didn't work because as soon as someone submits the form that does all the processing that page doesn't exist anymore so the popup closes right away.

What do you think?
 
Try letting the page you are opening create the
pop-up then once it's through loading it can close
it here's an example:
Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<html><head><title>TEST</title><script>
var nwwin = window.open();
  nwwin.document.write('<html><head></head><body> \n'+
  'This is a test </body></html>');
  nwwin.document.close;
  </script></head><body><center>
This is your real page<br>
we opened the pop-up in the<br>
header... Include the close(); at<br>
the end of the real html doc.<br>
I included a timeout for testing.<p>
Or  you could try placing the close()<br>
in the body onLoad
<script>setTimeout('nwwin.close()',5000);</script>
</body></html>

2b||!2b
 
hi,
this must work:
Code:
<body>
<script>
//code to open window (dont use the function name simply type window.open....
wn=window.open('animate.html')
</script>
<%
[b]response.flush()[/b]
'asp ulpoad code here
%>
<script>
wn.close()
</script>

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top