Forum Moderators: open
Calm down, calm down.
I'm talking about a pop up window we use in our back office online system.
It is appropriate for the system to open a pop up window for staff to enter some additional information to export a customers details.
When the staff member hits enter and system processes it lands at a 'completed' screen. Is it possible, using JavaScript, to automatically close this window?
I tried using the onload="self.close();" but I think that the window is closing before the ASP code is executed.
Thanks
Mick
Calm down, calm down.
Haha, not all pop up windows are evil. :-)
Do it something like this. My ASP is rusty so I'll use "baby-code" for the logic.
if ([some element in the submitted form]) {
--> Do your script functions here
--> Now output this as a response after doing the functions:
<script type="text/javascript">
window.onload=function () { setTimeout('window.close\(\)',5000); };
document.write('Closing window in five seconds, thank you!'); }
</script>
}
else {
output your form here, with "some element in the form" as a trigger for the above action.
}
You can eliminate the setTimeout if you want:
<script type="text/javascript">
window.onload=function () { window.close(); };
</script>
The important part is this must come after your server side script does it's work. You must always return a response or you get a server error or "white page."
I know what you guys are saying but, when I tested it with an onload="self.close();" I *think* that the window closed before the ASP had completed. Could be wrong there, but I feel better trying the wait 5 seconds version.
Thanks
<html><head></head>
(javascript code here)
<body>
<%
' do some server side function
Response.write("ending function")
%>
</body></html>
This is what I meant, do all the functions first so the very last thing is to output to browser.
<%
' do some server side function
%>
<html><head></head>
(javascript code here)
<body>
<p>closing window</p>
</body></html>
1. Browser sends HTTP request to server
2. Server sees that it's for an ASP page, and all ASP is processed on the server.
3. The resulting output is sent as the response back to the client.
So, for example, if suppose your markup looked like this:
<html><head>
<script>...</script>
</head>
<body>
<%
Response.write('foo')
%>
</body></html>
Then the HTML response that gets sent back to the browser will look like this:
<html><head>
<script>...</script>
</head>
<body>
foo
</body></html>
The ASP code has already been processed by the time the JavaScript code executes.
Since then I have implemented Rockinbil's delayed timeout and there are no problems and the staff seem happy enough.
I'll just leave it as it is as I have too much to do to revisit old problems!
Thanks