Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing a Pop-up window

Status
Not open for further replies.

MP498T

MIS
Mar 14, 2001
15
GB
I have an asp page that's extracting data via scripts from a database, the extracts takes awhile to populate the page (variable time from seconds to minutes).

To keep the user informed I've created a pop-up box that asks them to 'please-wait' and once the data extracted has populated the page I'm able to close the pop-up. Where I'm struggling is if the users aborts the original page, by either hitting 'back' or their 'home icon' on the toolbar, the stop button, or indeed the 'x' on the top right of the window before the page finishes loading, the pop-up box remains in place. See code below.

How do I close the pop-up if the openner is closed or 'aborted' from? I tried
Code:
 <BODY onUnLoad=&quot;closeNewWindow()&quot;>
with no success. Can it be done from the pop-up so it closes itself if it's openner 'disappears'?

Jason.

Code:
<HTML>
 <HEAD>
  <TITLE>List of Invoices</TITLE>
   <SCRIPT LANGUAGE=&quot;JavaScript&quot;>
    var newWindow
    function makeNewWindow() {
     newWindow = window.open(&quot;inprogress.htm&quot;,&quot;&quot;,&quot;height=200,width=300&quot;)
    }
    function closeNewWindow() {
     if (newWindow) {
          newWindow.close()
     }
    }
   </SCRIPT>
 </HEAD>
 <BODY>
  <script Language=&quot;javascript&quot;>
   makeNewWindow()
  </script>

 <%Call subDataExtract(variable)%>

  <script Language=&quot;javascript&quot;>
   closeNewWindow()
  </script>
 </body>
</html>
 
I tried you're version of
Code:
<body onunload=&quot;closeNewWindow()&quot;>
in case it was the capitalisation in my version but still no good.

To prove that the onunload worked I changed it to
Code:
<body onunload=&quot;makeNewWindow()&quot;>
and when I hit the home button up pops the new window BUT only if the page has completed loading, if I hit the home button before the page has fully loaded it doesn't pop-up.

So I assume the onunload doesn't working before the page has fully loaded, i.e. not until the the </BODY> tag is written.

Thanks anyway, but I'm still looking.
Jason.
 
on the popup have this bit of code :

<script>
function checkOpener()
{
if (!opener)
{
self.close();
}
setTimeout(&quot;checkOpener()&quot;, 500)
}
</script>

<body onload=&quot;checkOpener()&quot;> Gary Haran
 
did you try putting:

window.onunload = closeNewWindow;

in the script tag in the head section
 
xutopia,

your code isn't working for me in IE 5.5:

<html>
<head>
<title>check opener</title>

<script name=&quot;javascript&quot;>
function makeNew() {
nw = window.open('','','width=350,height=300');
nw.document.writeln('<html>\n<head>\n<scr' + 'ipt language=&quot;javascript&quot;>function checkOpener() {');
nw.document.writeln('if (!opener) {self.close();}');
nw.document.writeln('setTimeout(&quot;checkOpener()&quot;,500);');
nw.document.writeln('}\n</scr' + 'ipt>\n</head>\n<body onload=&quot;checkOpener();&quot;>\n body text...\n</body>\n</html>');
}
</script>

<style type=&quot;text/css&quot;>
</style>

</head>

<body onload=&quot;&quot;>
<input type=&quot;button&quot; name=&quot;&quot; value=&quot;makeNew&quot; onclick=&quot;makeNew();&quot; />
</body>
</html>

=============================================================================== ======================================

if (!succeed) try++
-jeff
 
I am using mozilla and IE6. Try doing an alert(opener) in your popup as well as an alert(parent) to see what that gives you. I'm just insterested. :) Gary Haran
 
xutopia,

yeah, i also tried just creating an alert in body onload...it doesn't work when the window is created/launched, but it does work when the window is refreshed.

this produces strange results in IE 5.5:
Code:
<html>
<head>
<title>check opener</title>

<script name=&quot;javascript&quot;>
function makeNew() {
	nw = window.open('','','width=350,height=300');
	nw.document.writeln('<html>\n<head>\n<scr' + 'ipt language=&quot;javascript&quot;>function checkOpener() {');
	nw.document.writeln('if (!opener) {self.close();}');
	nw.document.writeln('document.body.innerText += (opener && !opener.closed) + &quot;, &quot;');
	nw.document.writeln('setTimeout(&quot;checkOpener()&quot;,500);');
	nw.document.writeln('}\n</scr' + 'ipt>\n</head>\n<body onload=&quot;alert(\'foo\');checkOpener();&quot;>\n body text...\n</body>\n</html>');
}
</script>

<style type=&quot;text/css&quot;>
</style>

</head>

<body onload=&quot;&quot;>
<input type=&quot;button&quot; name=&quot;&quot; value=&quot;makeNew&quot; onclick=&quot;makeNew();&quot; />
</body>
</html>

when first launched, the new window does nothing. when refreshed, the alert happens, then &quot;true&quot; is appended to the body. if the opener is closed however, the new window doesn't close.

even stranger: if the opener is closed before refreshing the new window, refreshing the new window produces the alert and &quot;false&quot; being appended to the body...this should be triggering self.close()!
======================================

if (!succeed) try++
-jeff
 
I have another question could you try it without doing a document.write from the opening page? Have a static HTML page and try it. :) Gary Haran
 
you mean same as above minus this line?

nw.document.writeln('document.body.innerText += (opener && !opener.closed) + &quot;, &quot;');


result is the same. no alert unless you refresh, and the new window will not close itself before or after.
======================================

if (!succeed) try++
-jeff
 
Try this:
function closeNewWindow() {
if (newWindow) {
newWindow.hide()
}
}

<body onUnLoad=&quot;closeNewWindow()&quot;>

Rick

P.S.--capitalization NEVER matters for html stuff, only other languages. If I have helped you just click the first link below to let me know :)
 
rick,

that'll probably work fine from the opener window. what we're testing here is script written dynamically to the new window.

xutopia,

worse yet: if I use this in NS 6:
Code:
<html>
<head>
<title>check opener</title>

<script name=&quot;javascript&quot;>
function makeNew() {
	nw = window.open('','','width=350,height=300');
	nw.document.writeln('<html>\n<head>\n<body onload=&quot;alert(\'foo\');&quot;>\n body text...\n</body>\n</html>');
}
</script>

</head>

<body onload=&quot;&quot;>
<input type=&quot;button&quot; name=&quot;&quot; value=&quot;makeNew&quot; onclick=&quot;makeNew();&quot; />
</body>
</html>

...the new window displays &quot;body text...&quot;, but I get no alert, and I get the busy cursor and the new window will not reload.

======================================

if (!succeed) try++
-jeff
 
It makes sense that the user's popup window doesn't go away since the server is still feeding
Code:
subDataExtract(variable)
to the browser when the user punches out. The
Code:
closeNewWindow()
command is still sitting on the server, waiting its turn to serve.

To keep things tidy we must give the user's browser a logically complete web page before we've loaded all of the page's elements. One way to do this is move the data extract function into a standalone page with an
Code:
onload=&quot;parent.closeLoading();&quot;
in its body tag. The base page loads with &quot;in progess ...&quot; showing, starts the data extract loading into an inline frame by linking via the
Code:
src
property of the inline frame. When the data extract page loads it yanks
Code:
closeLoading()
which can hide the &quot;in progress ...&quot; and reveal the data extract frame.

In this progression a bored or distracted user can steer his browser elsewhere without leaving any new windows unclosed. This sounds easier than trying to establish working communications between a child window and a not-fully-loaded parent window.
 
I understood that you're trying to find a way to close the popup window when the &quot;popper&quot; window either gets closed or goes to a different page. That's what it seems most of the posts here are talking about. If you don't thatn try this idea.

I'm assuming that you are using a while or a for loop recursively to feed the data into the window, right? If so, just put the if(!opener){whatever works to close it}. That way it won't have to wait for the whole thing to finish; it'll check after every record.

Rick
If I have helped you just click the first link below to let me know :)
 
wray,

makes sense...

adding document.close(); gets the alert to happen now, but it still stays open when I close the opener.


======================================

if (!succeed) try++
-jeff
 
Thank you all for you time.

The option I've settled for is to use Frames. The initial page is a frame set consisting of two frames &quot;Top&quot; and &quot;Botom&quot;. Top is 'hidden' being of zero size and contains only the script to pop-up the processing window and an onunload script to close it. Once the &quot;Bottom&quot; loads (onload) it changes the top frame to another page (of zero content and size) causing the original &quot;Top&quot; to unload and thus the processing pop-up is closed. If the user goes somewhere else before the bottom finishes loading Top is unloaded and pop-up processing closes (unless they abort very quickly which is unlikely)

Thank again
Jason.
 
Further follow up. The frames idea didn't work either if the user hit home before the bottom frame had completed. However on speaking to a colleague he pointed me to the following line of code

Code:
showModelessDialog(&quot;inprogress.htm&quot;,&quot;&quot;,&quot;center=yes; help:no; resizable:no; status:off;dialogWidth:300px; dialogHeight:200px&quot;);

Which if you use in place of the code
Code:
 newWindow = window.open(&quot;inprogress.htm&quot;,&quot;&quot;,&quot;height=200,width=300&quot;)
in the original function makeNewWindow() - and combine with the frames idea - works incredible well, I've no idea what it's doing as my Javascript reference book doesn't mention it, but it works.

Jason.
 
Jason,

Google for showModelessDialog went straight to MSDN where apparently (I've never really gotten the hang of MicroSpeak) Modeless means NOT Modal; Modal meaning &quot;hang all browser resources until you click a button&quot;. The example confirms that Modeless behaves quite nicely, goes away when one leaves the page. If so, you should be able to get by without frames by replacing window.open with the Modeless thingie.

Of course this is IE specific. But if that's not a problem then you can probably use data binding (look up the Tabular Data Control at MSDN) to break the List of Invoices into pages, dramatically reduce wait time for the user.

Wray

The wheel wasn't reinvented in a day.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top