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 Mike Lewis 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() to work without having to click on it...

Status
Not open for further replies.

Ovatvvon

Programmer
Feb 1, 2001
1,514
0
0
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
 
place the code when you wanna close the window.

<script language=javascript>
<!--
window.close();
//-->
</script>

is that what you want?
 
that asks for a confirmation by the user if they really want to close their browser. I am performing an autotask in a secondary window, so I don't want the user to have to be bothered and annoyed with msg box's keep popping up asking for confirmations. Want it to shut auto. Like when you click on a link as I demonstrated above, it doesn't ask for confirmation.
-Ovatvvon :-Q
 
I giving u a sample code which automatically closes the window, after 10 sec. U can also do the same after perfoming some function. The code which closes the window after 10 sec is...

<html>
<head>
<title>Window open only for some time</title>
<script>
function closeCall()
{
window.close();
}
function autoCall()
{
setTimeout('closeCall()','1000');
}
</script>
<body onLoad=&quot;autoCall();&quot;>
<p> This window will close automatically after 10 sec</p>
</body>
</html>

 
I giving u a sample code which automatically closes the window, after 10 sec. U can also do the same after perfoming some function. The code which closes the window after 10 sec is...

<html>
<head>
<title>Window open only for some time</title>
<script>
function closeCall()
{
window.close();
}
function autoCall()
{
setTimeout('closeCall()','1000');
}
</script>
<body onLoad=&quot;autoCall();&quot;>
<p> This window will close automatically after 10 sec</p>
</body>
</html>

hope this solves yr problem

Madhavan

 
First of all, Thanks for supplying me with the exact code i am after for my application.

One issue i do have though, is that IE comes up with a message box after 10 seconds and says, &quot;The web page you are viewing is trying to close the window, Do you want to close the window? YES/NO.&quot;

Is there anyway of getting Internet Explorer to NOT display this message???

Cheers Nunners.
 
You can only use window.close to close windows your code has created. If you try to use window.close on the browser session the user opened it will always prompt the user.

This is a security feature of Internet Explorer (don't know about netscape) and cannot be disabled in code.
 
Well, IE comes up with a message box only if the window is a parent window. If you put the code by madhavaa123 above in a child window, the message box won't come up :)
 
Here is an tip
&quot;
Invoking the window.close method on a window not opened with script will display a confirmation dialog box. Using script to close the last running instance of Microsoft® Internet Explorer also opens the confirmation dialog box
&quot;

If u want to close the window by the script u have to create the window with
window.open method...

hope this gives u ideas... ________

George
 
Cheers people, once i have created the window with window.open i can close it at my will.........

great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top