Solved

popup window during upload

Posted on 2004-08-02
5
690 Views
Last Modified: 2012-05-05
Hi
I'm looking for a javascript which opens a popup window (child) during upload.

Checked already some solutions - but I have som trouble closing the child window after upload is finished.

I guess the parent window which starts the upload must have something like <body onload='childwindow.close;'> to close the child window when upload is complete??
Its not working yet...

Here is the code used so far by the parent:

function DoUpload() {
  childwindow= window.open('uploadprogress.php');
}

....
<FORM enctype='multipart/form-data' action='$uploadname' method='POST' name='myform' >
....
<INPUT TYPE=submit VALUE='go' OnClick='DoUpload()'>

the above code opens a new window, but how does it close after upload process ?
Thanks for your help.
Mathias
0
Comment
Question by:mfuerlinger
5 Comments
 
LVL 2

Expert Comment

by:Michael_Cicogna
ID: 11699272
Hi

Your idea should work well if you use the onUnload Event instead of the onload.

Michael
0
 
LVL 7

Expert Comment

by:Xxavier
ID: 11699307
It is

onload='childwindow.close()'
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 180 total points
ID: 11701306
My proposal is this:

function DoUpload() {
  childwindow= window.open('uploadprogress.php');
  window.onunload = function(){childwindow.close()};
}


0
 
LVL 1

Author Comment

by:mfuerlinger
ID: 11706254
Zvonkos suggestions works fine for me: A tiny, easy and sexy sniplet. Thanks.

Here is the complete code in one file to open and close a window during file upload (embedded in php):

<?php
echo "
<HTML>
<HEAD><TITLE>UPLOAD</TITLE>
<SCRIPT LANGUAGE='JavaScript'>
function DoUpload() {
  theFeats =   'height=120,width=500,location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no';
  theUniqueID = (new Date()).getTime() % 1000000000;
  childwindow = window.open('uploadprogress.php', theFeats);
  window.onunload = function(){childwindow.close()};
}
//-->
</SCRIPT>
</HEAD><BODY>
<FORM enctype='multipart/form-data' action='uploadtest.php' method='POST' name='myform'>

new files:
<INPUT TYPE=file NAME='filename' SIZE=25>
<INPUT TYPE=submit VALUE='go' OnClick='DoUpload()'>

</FORM>
</BODY></HTML>
";
?>


enjoy.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11707599
Thanks for points.
But you should change your script.
Like this:

<?php
echo "
<HTML>
<HEAD><TITLE>UPLOAD</TITLE>
<SCRIPT LANGUAGE='JavaScript'>
function DoUpload() {
  theFeats =   'height=120,width=500';
  childwindow = window.open('uploadprogress.php', 'Progress', theFeats);
  window.onunload = function(){childwindow.close()};
}
//-->
</SCRIPT>
</HEAD><BODY>
<FORM enctype='multipart/form-data' action='uploadtest.php' method='POST' name='myform'>

new files:
<INPUT TYPE=file NAME='filename' SIZE=25>
<INPUT TYPE=submit VALUE='go' OnClick='DoUpload()'>

</FORM>
</BODY></HTML>
";
?>
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question