Solved

popup window during upload

Posted on 2004-08-02
5
680 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now