Current location: Hot Scripts Forums » General Web Coding » JavaScript » Your File is uploading Popup


Your File is uploading Popup

Reply
  #1 (permalink)  
Old 03-16-07, 04:28 PM
scott2500uk's Avatar
scott2500uk scott2500uk is offline
Coding Addict
 
Join Date: Apr 2006
Posts: 275
Thanks: 2
Thanked 2 Times in 2 Posts
Your File is uploading Popup

I have a simple file uploader. user selects file and it uploads. Depending on siz eof file the page could take ages to change or matter of seconds which then shows if the file uploaded or not.

I want to add a popup that shows an image saying uploading while the file is uploading. this is to tell the user that the file is actually being uploaded and to wait patiently.

Now i have the popup to open when they submit the form with the following code:

PHP Code:

echo "<form method='post' enctype='multipart/form-data' action='' onSubmit='imuploading()' /><br>"
Code:
function imuploading() {
	var windowuploading = null;
	var w = '260';
	var h = '160';
	var mypage = '';
	var myname = 'Uploading';
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings ='height='+h+',';
	settings +='width='+w+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='scrollbars=no,';
	settings +='resizable=no';
	windowuploading = window.open(mypage,myname,settings);
	if(parseInt(navigator.appVersion) >= 4){
		windowuploading.window.focus();
	}
	windowuploading.document.writeln("<center><img src='modules/File_Uploader/images/loading.gif' alt='Uploading' /></center>"); 
}
What has had me stuck for hours is how to close that popup when the main page has finished uploading and has given some output.

Now ive tried using methods such as onUnload=closemypopup() onLoadclosemypopup() and used js to tell the popup to close:

Code:
function closemypopup() {
    windowuploading.close();
}
But these just dont work for some reason. I get js errors saying that windowuploading is undefined. I presume this is because the main page has changed.

Now I have found a way to acomplish what i want but its just not practical. and that is when the main page has refreshed is put on that page to open the same popup and then close it. Because the same popup is being opened instead of 2 popups it just refreshes the first one.

For a visual demo go to: http://www.steezmatic-designs.com/mo...=File_Uploader

You can see the popup open. Im looking for a way to close it once the main page has finished uploading.

Some one please help me. thank you.
Reply With Quote
  #2 (permalink)  
Old 03-17-07, 01:24 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
The reason you get "windowuploading is undefined" is because it only exists in the local scope of the imuploading function. As soon as that function returns, the windowuploading variable is destroyed.

To access the variable from closemypopup, make it global by simply moving the declaration out of the function:
javascript Code:
  1. var windowuploading = null;
  2. function imuploading() {
  3. .....
  4. }

It's also possible to simply neglect the var keyword. Then the variable defaults to global scope, but I don't recommend that since it causes confusion and possible conflicts.
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Reply With Quote
  #3 (permalink)  
Old 03-19-07, 11:11 AM
scott2500uk's Avatar
scott2500uk scott2500uk is offline
Coding Addict
 
Join Date: Apr 2006
Posts: 275
Thanks: 2
Thanked 2 Times in 2 Posts
ok i have moved the variable outside the function so now my js code is:

Javascript Code:
  1. var windowuploading = null;
  2.  
  3. function uploadwindow() {
  4.     windowuploading.close();
  5. }
  6.  
  7. function imuploading() {
  8.     var w = '260';
  9.     var h = '160';
  10.     var mypage = '';
  11.     var myname = 'Uploading';
  12.     var winl = (screen.width-w)/2;
  13.     var wint = (screen.height-h)/2;
  14.     var settings ='height='+h+',';
  15.     settings +='width='+w+',';
  16.     settings +='top='+wint+',';
  17.     settings +='left='+winl+',';
  18.     settings +='scrollbars=no,';
  19.     settings +='resizable=no';
  20.     windowuploading = window.open(mypage,myname,settings);
  21.     if(parseInt(navigator.appVersion) >= 4){
  22.         windowuploading.window.focus();
  23.     }
  24.     windowuploading.document.writeln("<center><img src='modules/File_Uploader/images/loading.gif' alt='Uploading' /></center>");
  25. }

now when the submit button is pressed once again the popup opens but when the file has finished and the main page has finished loading the popup doesnt close. Im am calling the function uploadwindow() by:

HTML Code:
<body onLoad='uploadwindow()'>
I use FF error console and the error im getting is:

windowuploading has no properties

and is pointing to this code:

Javascript Code:
  1. function uploadwindow() {
  2.     windowuploading.close();
  3. }

Looks like when the page refreshes its loosing the popup that opened

Last edited by UnrealEd; 03-19-07 at 12:02 PM. Reason: please use the correct code syntax highlighters when posting code
Reply With Quote
  #4 (permalink)  
Old 03-19-07, 06:01 PM
jfulton's Avatar
jfulton jfulton is offline
Community VIP
 
Join Date: Apr 2006
Location: Los Angeles, CA
Posts: 660
Thanks: 0
Thanked 0 Times in 0 Posts
When are you trying to close the popup? Is it after the "main window" refreshes or changes? If you have a main window open a popup, the reference to that popup from the main window is only available while that main window remains on the same page. As soon as you navigate the main window to a new page, or refresh the page, the javascript code is all "new" - so your windowuploading variable is set to null. The only time windowuploading is not null is after the popup has been opened and the main page has not changed.

HTH.
Reply With Quote
  #5 (permalink)  
Old 03-20-07, 07:43 AM
scott2500uk's Avatar
scott2500uk scott2500uk is offline
Coding Addict
 
Join Date: Apr 2006
Posts: 275
Thanks: 2
Thanked 2 Times in 2 Posts
Thats what i thought so knew there was no way to close the window. but I found away and that was to reopen the popup with the same param's and tell it too close. what I want to know is this the only way?
Reply With Quote
  #6 (permalink)  
Old 03-20-07, 07:51 AM
scott2500uk's Avatar
scott2500uk scott2500uk is offline
Coding Addict
 
Join Date: Apr 2006
Posts: 275
Thanks: 2
Thanked 2 Times in 2 Posts
ok this is how im making it work as i want:

I open popup with onSubmit
main page reloads
on the new page load i have the code:

Javascript Code:
  1. imuploading();
  2. uploadwindow()

This reopens the same popup and then closes it.

This works on IE7 and FF.

any one tell me if it aint working in other browsers or if there is a better way of achieving this?

cheers for all your help

Last edited by UnrealEd; 03-20-07 at 09:04 AM. Reason: please use the correct code syntax highlighters when posting code
Reply With Quote
  #7 (permalink)  
Old 03-20-07, 05:36 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
Oh sorry, I forgot the main page refreshed before you wanted to close the popup.

One way to do it is like you suggested, open a new window with the same name as the old one (the second parameter to the window.open() method), if the window already exists, the browser should notice this and instead of creating a new window, return a reference to the one already open. When doing so, the browser also ignores the third parameter, defining the window style, since windows can only change styles upon creation.
On a side note, I noticed this behaviour in a gallery on a site I recently made, where all the images would open up in the same popup, without the popup being resized as the designer intended.

Another way to be sure you get the correct window is to store the windowuploading variable with the reference to the window in a hidden frame.

That way you can access the frame after a page refresh and look up that variable. But adding frames and stuff to your site just for that probably isn't an ideal solution.

Yet another method would be to take advantage of the window.opener reference in the popup. (This should still be valid after the main page refreshes) A small script could "poll" the main window and add a reference to itself in a variable there, allowing the main window access to it again.
Of course, the main window would have to cooperate with the popup and "listen" for a reference update if it finds that the variable is null when it tries to close the window.
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Uploading file Deansatch PHP 10 07-24-06 10:33 AM
showing realtime percentage of uploading file tallpaul858 PHP 2 06-01-05 02:04 PM
file uploading jaishalg PHP 1 06-22-04 11:54 AM


All times are GMT -5. The time now is 11:25 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.