View Full Version : close current window?

03-11-2003, 02:25 AM
Is there a way to close the current window in PHP. Something similar to the JS version of window.closw() but I want it to work when it reaches a point in the code...the end of the code where when I put JS there it just closes as soon as it opens.


03-11-2003, 03:48 AM
Write yourself a lil algorithm - if you want it on a command button, do this:

<input type="submit" onClick="<? $submit=1; ?>">

And at the end of the script:

if($submit == '1') {
echo "<script>window.Close</script>";

Something like that...

03-11-2003, 05:04 AM
PHP cannot close a browser window. PHP runs on the server. PHP sends only client side coding such as HTML, Javascript to the browser. So if you wish to close a browser window you will need to use javascript but as Phantom has pointed out you can use PHP to write the necessary javascript to close the browse window.

03-11-2003, 11:08 PM
ok, so I tried that code: I used
<input type="submit" onClick="<? $close=1; ?>">

And at the end of the script I put:


if($close== '1') {
echo "<script>window.close()</script>";

But for some reason the window won't open. Its like it reads the javascript longbefore the PHP or something. Any suggestion?


03-11-2003, 11:33 PM
Where are you opening the window? Post some more of your PHP code.

If you want the window to close itself you should use self.close() instead of window.close()

You can even set a timeout for how quickly the window should close after it's been open.

Here's the code for setting the timeout:

<script>setTimeout("self.close()",1000);</script>The part in red you can change to the milliseconds you want it to wait for.