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!

javascript:window.close() without having to click on it?

Status
Not open for further replies.

Ovatvvon

Programmer
Feb 1, 2001
1,514
US
How can I get the browser to close without the user having to close the browser themselves or click on anything?

I know I can put:

<A href='JAVASCRIPT:window.close();'>Close it</a>

So when they click on the link, it'll close the window, but I have it setup so a small window opens briefly to perform a task and I want it to close when it is done.

Can anyone tell me this? It's probably really simple, huh?
-Ovatvvon :-Q
 
I use a version of this:

<SCRIPT LANGUAGE=JavaScript>
this.window.close();
</SCRIPT>

I hope this helps!

Joe
 
good, however one problem. Since it is an automatic task, having a message window pop up every time asking the user if they 'really' want to close the window would get annoying. When clicking on the javascript link that I mentioned above, it doesn't ask for confirmation, it just closes it. This is what I would like to accomplish.

Any Ideas?
-Ovatvvon :-Q
 
Hmmm, it does not pop-up an alert for me. I use this little snip of code all by itself on an HTML page. I redirect out of an ASP page to the page with just this code and it just closes down. No messages or anything.

I am curious why you would get a message and I don't...

Joe
 
Near as I figure, if you open a window using JavaScript, you can close it using JavaScript... without having an alert pop-up.

I can do that as often as I like, but if I go straight to the window with the close code I get the prompt.

Can you create your window using JS? That *may* solve your problem...

Joe
 
lol...ok, here is:

I did create it with javascript. but when I was testing it, I went straight to the page, which like you said, gives the error, however if going auto from one page to another, and such, it closes with no problem. I found this out right before you sent the message stating that, so kinda cool that we found out same time. But thanks for your help!

-Ovatvvon :-Q
 
Hi ovatvvon

If I understand your question well you only want to open a window and close it.

If you mean to open that child-window from code in the parent-window you can do it with this code in you parent-window:

<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
{
window.open('url', 'windowname', 'top=200,left=100,height=250,width=274');
var blabla = window.open('url', 'windowname');
}
</script>

blabla is to get it closed later.

Now you can code your tasks and after that you can close it with this code (stil in your parent-window):

<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
{
blabla.close();
}

</script>

 
i am also getting the confimaiton message when i close a window with javascript. i read the posted solution but i am redirecting from another page. any idea on how to get around that??

thanks,
--jimmy
 
i would put this at the bottom of the page for a timed closing:

<script language=&quot;JavaScript&quot;>
<!--
setTimeout('window.self.close()',3000);
//-->
</script>

hope it's useful to ya ~ jsLove ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top