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

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
PaulCutcliffeAsked:
Who is Participating?
 
NetGrooveConnect With a Mentor Commented:
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
 
NushiCommented:
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
 
devicCommented:
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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
devicCommented:
oops, i mean in in 3 step:

<script>
   var PleaseWaitWinClose=true;
</script>
0
 
devicCommented:
or better in 3 step:

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

<body onload="PleaseWaitWinClose=true">
0
 
jwyrickCommented:
try this

function closePleaseWait() {
      parent.pleaseWait.close();
   }
0
 
NetGrooveCommented:
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
 
PaulCutcliffeAuthor Commented:
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
 
PaulCutcliffeAuthor Commented:
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
 
PaulCutcliffeAuthor Commented:
Sorry, thought I'd accepted your answer already. I'll do it now.

It worked a treat, by the way, thanks.
0
 
NetGrooveCommented:
You are welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.