PDA

View Full Version : How to close window after processing code?


DiaH
09-18-2002, 04:37 PM
Let me see if I can explain this clearly. I have window A that has a link on it. When the user clicks the link on window A, it opens window B. When the user clicks the submit button on window B, it submits to another page within window B but is not visible to the user (no html code, just script code). Upon completion of the processing I want window B to close.

I have in the button on window B the following:

function B1_onclick() {
document.frmEditMetrics.action="ProcessInsertMetricEdits.asp?MetricID=" + document.frmEditMetrics.MetricID.value;
window.close();
}

The problem is the close happens so fast(?) that the processing doesn't happen in the page in Netscape 6.2. It works fine in IE5.5. I need it to work in both browsers.

Help!!
Thanks,
Dia

Roy Sinclair
09-18-2002, 05:23 PM
Use a setTimeout call to delay the close for a second:


setTimeout("self.close();",1000)

DiaH
09-18-2002, 06:25 PM
Unfortunately that didn't work either. I put it where I had the window.close(); and it still didn't close the window.

I don't think its executing. I just changed it from setTimeout("self.close();", 1000); to setTimeout("alert('times up');", 1000); and the alert never came up.

Am i putting it in the wrong spot?

DiaH
09-18-2002, 06:32 PM
I don't know what the deal is but I changed it to this:

window.setTimeout("window.close();",100);

and it worked.

Much thanks!!!!!
Dia :thumbsup:

glenngv
09-19-2002, 02:49 AM
you can do it without setTimeout.

in your ProcessInsertMetricEdits.asp which is your action page:

<%

'asp codes here

%>

<html>
<head>
<script>window.close();</script>
</head>
<body>
</body>
</html>


then in your onclick function:

function B1_onclick() {
document.frmEditMetrics.action="ProcessInsertMetricEdits.asp?MetricID=" + document.frmEditMetrics.MetricID.value;
}

that's the safest thing to do. :)
have the control of closing the window on the next page not on the calling page.

DiaH
09-19-2002, 01:37 PM
Sounded like a great thing to try, Glenn, but it doesn't work well in netscape. Netscape left the second window open.

glenngv
09-20-2002, 01:54 AM
Originally posted by DiaH
Sounded like a great thing to try, Glenn, but it doesn't work well in netscape. Netscape left the second window open.

make sure that there is no response.end (or response.redirect) in your asp code
could you pls view the html source of the opened window. can you see the html code generated like the one below?

<%

'asp codes here


'there should be no
'response.end
'here
%>

<html>
<head>
<script>window.close();</script>
</head>
<body>
</body>
</html>

DiaH
09-20-2002, 01:03 PM
There is a response.redirect at the end of the page that is for the parent window. Perhaps that is what the problem is.

glenngv
09-23-2002, 01:42 AM
why do you have to redirect to another page when you just want to close the window?

DiaH
09-23-2002, 01:07 PM
Its a redirect for the parent page upon closing the child window.