Solved

Popup window: "Please wait while your file is submitted..." - how to close again from the "Thank you, your file has been submitted" window?

Posted on 2003-11-09
11
938 Views
Last Modified: 2010-05-18
I am developing a website which enables users to submit files, some if which are quite big (realtive to the connection speed). Sadly, my JavaScript abilities are very limited, so I'm struggling with quite a simple bit.

So the user doesn't give up waiting for the file transfer, I have made it open a second browser window, with a message saying "Please wait while your file is submitted", with an hourglass animate GIF.

This all works nicely so far, from a line saying:

   windowPleaseWait = window.open('pleasewait.html', 'windowPleaseWait', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=600,height=200,left=200,top=200');

Now, all I want to do is close this Window, if it's open, from the new window that says "Thank you, your file has been submitted". I'm using a line like this:

   pleaseWait.close();

But, as this is a new page, it doesn't seem to know what 'pleaseWait' is.

I know this because, if I open the window & then close it from within the same window, it works, by calling these functions, for example:

   function openPleaseWait() {
      pleaseWait = window.open('http:pleasewait.html', 'PleaseWait', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=600, height=200, left=200, top=200');
      pleaseWait.focus;
   }

   function closePleaseWait() {
      pleaseWait.close();
   }

So, my question is, how can I get a hold of this popup window from within the new page? This new page appears in the same browser window as the one that opened the popup window, if you follow - I know you can't close windows you didn't open.

Any help appreciated,

Paul
0
Comment
Question by:PaulCutcliffe
  • 3
  • 3
  • 3
  • +2
11 Comments
 
LVL 10

Expert Comment

by:Nushi
ID: 9709621
hi there.

you can do a small trick which will work.
instead of submitting the original page (top)
use frame/Iframe and sent all teh data from there.

(do the submit form the inner frame)
in this way you wont lose the pleaseWait womdow and you will be able to close him,
simply by using JS from the retuned page.

FRAME -> SUBMIT -> call JS function in the top frame which close the pleaseWait.

Nushi.


0
 
LVL 25

Expert Comment

by:devic
ID: 9709735
hi PaulCutcliffe,

1. add in your main page:
==================================
<script>
    var PleaseWaitWinClose=false;
</script>

2. in popup add this:
==================================
<script>
function checkOpener()
{
      if(!opener.PleaseWaitWinClose)
      {
            setTimeout("checkOpener()",100)
      }
      else
      {
            self.close();
      }
}
checkOpener();
</script>

3.in new page insert this:
===============================
<script>
    var PleaseWaitWinClose=false;
</script>
0
 
LVL 25

Expert Comment

by:devic
ID: 9709740
oops, i mean in in 3 step:

<script>
   var PleaseWaitWinClose=true;
</script>
0
 
LVL 25

Expert Comment

by:devic
ID: 9709741
or better in 3 step:

<script>
   var PleaseWaitWinClose=false;
</script>

<body onload="PleaseWaitWinClose=true">
0
 
LVL 2

Expert Comment

by:jwyrick
ID: 9711430
try this

function closePleaseWait() {
      parent.pleaseWait.close();
   }
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 10

Expert Comment

by:NetGroove
ID: 9711549
Here is my trick:

Your origianal window opens the popup like you stated:

 function openPleaseWait() {
     pleaseWait = window.open('http:pleasewait.html', 'PleaseWait', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=600, height=200, left=200, top=200');
     pleaseWait.focus;
  }



Now your Thank You page can do a simmelar call and close the popup.
Like this:

  function closePleaseWait() {
     pleaseWait = window.open('', 'PleaseWait');
     pleaseWait.close();
  }


The trick is that the popup gets the window name from the secons parameter in window.open()
Reopening a new window with same window name fetches the same previously opened popup window and you can close it.

Good luck,
NetGroove

0
 

Author Comment

by:PaulCutcliffe
ID: 9711746
Thank you NetGroove, perfect. I actually did this in the onUnLoad event of the page that opened it, but the principle was the same.

One thing though, the page sometimes closes without having opened the popup, for example if the user  cancels instead of submitting a file. Is there an way of checking? Otherwise, when the other window isn't opened, it flashes up another window. I thought of specifying the dimensions & things like that, but that would affect the real popup window too. Can I test for its presence before opening it?

Thanks
0
 
LVL 10

Accepted Solution

by:
NetGroove earned 300 total points
ID: 9711810
Sorry, there is no window detection without holding an object link or reference to that popup window.

Only trick I can recommend is to open the closing window on the far right bottom side, let say 20000 pixel.
Like this:

  function closePleaseWait() {
     pleaseWait = window.open('', 'PleaseWait', 'left=20000, top=20000');
     pleaseWait.close();
  }


0
 

Author Comment

by:PaulCutcliffe
ID: 9714027
Yeah, I was going to try that, but was worried about whether the existing window would move to those coordinates before closing, but I'll try it now.

Thanks.
0
 

Author Comment

by:PaulCutcliffe
ID: 9730841
Sorry, thought I'd accepted your answer already. I'll do it now.

It worked a treat, by the way, thanks.
0
 
LVL 10

Expert Comment

by:NetGroove
ID: 9730869
You are welcome.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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…

757 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