closing the current window

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hanhao
Forum Newbie
Posts: 14
Joined: Mon May 22, 2006 10:58 am

closing the current window

Post by hanhao »

ok i need to self close a window (like after 5 seconds)

anyone knows the command to close the window?

would

Code: Select all

echo "self.close()";
?

be correct?

if not, please tell me what i have left out with a counter example

- hanhao
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Re: closing the current window

Post 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

Code: Select all

echo "self.close()";
?

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
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Re: closing the current window

Post 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.
User avatar
aerodromoi
Forum Contributor
Posts: 230
Joined: Sun May 07, 2006 5:21 am

Re: closing the current window

Post 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 :wink:
Post Reply