Page 1 of 1
closing the current window
Posted: Sun Jun 04, 2006 5:08 am
by hanhao
ok i need to self close a window (like after 5 seconds)
anyone knows the command to close the window?
would
?
be correct?
if not, please tell me what i have left out with a counter example
- hanhao
Re: closing the current window
Posted: Sun Jun 04, 2006 5:51 am
by aerodromoi
hanhao wrote:ok i need to self close a window (like after 5 seconds)
anyone knows the command to close the window?
would
?
be correct?
if not, please tell me what i have left out with a counter example
- hanhao
Again - you'll need JavaScript for that
Code: Select all
<body onLoad="setTimeout(window.close, 5000)">
aerodromoi
Re: closing the current window
Posted: Sun Jun 04, 2006 6:58 am
by bokehman
aerodromoi wrote:Code: Select all
<body onLoad="setTimeout(window.close, 5000)">
aerodromoi
Although that might work to some degree in IE it is not legal code and will be stopped by the sandbox in the Gecko browsers (and rightly so). The only window that may command the closure of a window is the one that opened it. Since a window cannot magically open itself code such as this is not ever going to work properly.
Re: closing the current window
Posted: Sun Jun 04, 2006 8:18 am
by aerodromoi
bokehman wrote:Although that might work to some degree in IE it is not legal code and will be stopped by the sandbox in the Gecko browsers (and rightly so). The only window that may command the closure of a window is the one that opened it. Since a window cannot magically open itself code such as this is not ever going to work properly.
So it would be something along that line:
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
var popupvar;
function openpopup(){
popupvar = window.open("http://www.google.com/", "Google","menubar=yes");
}
function closepopup(){
popupvar.close();
}
</script>
</head>
<body onLoad="openpopup(); setTimeout(closepopup(), 5000);">
</body>
</html>
aerodromoi
ps: I've never been too fond of JavaScript - you never know whether a user has it enabled or not. Ok, that's no explanation for the buggy snippet
