We help IT Professionals succeed at work.

Close browser window

suran78
suran78 asked
on
Experts,

I have a ASP submission form.  After user submits it, i want the ASP code to close the submission form after 1 min autmatically.  Please give me the code in asp/vbscript to close the submission window automatically.

Thanks.
suran
Comment
Watch Question

Joachim CarreinSr. Software Developer

Commented:
you'll need to do this with javascript. but then the user still gets a message (you want to close this window?)

Author

Commented:
Yes, that will work.  Please provide the code.
Thanks.
Joachim CarreinSr. Software Developer

Commented:
response.Write "<script language=javascript>window.close();</script>"
Joachim CarreinSr. Software Developer

Commented:
you can try this easy in your browser, in the address bar type javascript:window.close();
and press enter, this is what the users will get then

Author

Commented:
Shoudl this be pasted after submission button?  Which is the best location?

Author

Commented:
OK, but I want the window to close automatically after 1 min, if the user forget to close it after submitting the form.  Is there anyway to close the browser automatically?  And yes when the code behind closes it automatically after 1 min, it can ask the question "do you want to close?"

Add the code below to your page.

<SCRIPT>
function CloseWin()
{
window.close()
}
set Timeout("CloseWin()", 60000)
</SCRIPT>

Author

Commented:
It's not closing, I tried it:

<script Language="JAVAScript">
  function CloseWin()
{
window.close()
}
set Timeout("CloseWin()", 60000)

</script>

Author

Commented:
getting error "expected ;"
on line -  set Timeout("CloseWin()", 60000)
setTimeout is one word not two...
Sorry, my bad.

Author

Commented:
It worked.  Thanks.
But it does not repeat the question is the user click no.  Can it keep asking until the window is closed?
Yes, just add the setTimeout statement into the function after the window.close as below..

<script Language="JAVAScript">
function CloseWin()
{
window.close()
setTimeout("CloseWin()", 60000)
}
setTimeout("CloseWin()", 60000)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.