aspose file tools
The moose likes HTML, CSS and JavaScript and the fly likes How to close a window on its own after a delay? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "How to close a window on its own after a delay?" Watch "How to close a window on its own after a delay?" New topic
Author

How to close a window on its own after a delay?

Vanchi Nathan
Ranch Hand

Joined: Feb 24, 2004
Posts: 107
Hello all,
Here i have a problem, it is closing a window on its own after a certain delay, using JavaScript. In my code i'm using window.close() method to close the window, so it does, but i want to give some message and then close on its own after 3 seconds.
So, give me guidance on how to make it...
thanks in advance...


Best regards,<br /> <br />vanchin
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 411
If you want to show confirm/alert, the window will be closed AFTER user closes this confirm/alert dialog.
So, if you do:
setTimeout("self.close();", 3000);
alert("This window will be closed");
the window will be closed only afetr user hits "OK" on dialog.
If this is not what you want, and you want to close window, if user did not canceled closing in some interval, than you have to use DIV, SPAN or IFRAME instead of standart dialog.
so, if you have a function "showDialog", which brings up your own replacement for modal "Are you sure" or "It about to be closed" dialog,
The code will look like:
setTimeout("self.close();",3000);
showDialog();
now, If your dialog is "Are you sure" type, than it will have an input type=button, that defines onclick event handler, let say "dontClose".
so you code will look like:
window.closeTimer = setTimeout("self.close();",3000);
showDialog();
Here is the "Don't close" button:
<input type=button value="Don't close" onclick="if(window.closeTimer){clearTimeout(window.closeTimer)};">
Vanchi Nathan
Ranch Hand

Joined: Feb 24, 2004
Posts: 107
hi,
your tips were all useful to me... thanks a lot
 
jQuery in Action, 2nd edition
 
subject: How to close a window on its own after a delay?
 
Threads others viewed
explicit event enabling and window closing
Application Not signing out Authenticate customers
Regarding closing an applet
Using onUnload
Transparent frame using Robot class and its createScreenCapture() method - help pls!
IntelliJ Java IDE