View Full Version : Code for closing an internet page

09-21-2005, 03:06 PM
I've googled till my mouse is almost worn out, but no luck - Anyone know the php code for closing an internet page please?

Any help appreciated.


09-21-2005, 03:27 PM
There is no such thing AFAIK. You can close a popup window with javascript and possibly a browser window but since php is executed on the server is has no control over the users browser.

09-21-2005, 04:22 PM
With Nancy's post, I'm pretty certain that javascript can close the main browser window, but I seem to recall that it prompts the user to accept the force closing option for it.
So to sum it up - not with php you can't.

09-21-2005, 05:46 PM
PHP has no contro of the browser. JS can close browser WINDOWS if you a) enable JS and B) when the window is not opened by JS it will ask you if it should be closed.

09-21-2005, 08:19 PM
marek_mar is spot on.

i don't realy understand why you would want to close it. the user should decide if he wants to close it or not. i think that the closest you can get is moving the window so it drops out of sight, but that is not really accepted codingpractice ...

09-21-2005, 11:32 PM
If you want to close the window based on a test in PHP, you could try:

$onload = "";
if (myTestSucceeds) {
$onload = " onload='window.close();'";
<body<?php if ($onload) { ?><?=$onload?><?php } ?>>
page content

As mentioned before, if JavaScript didn't open the window, the user will be prompted to confirm the close, assuming JavaScript is enabled on their machine in the first place.


09-22-2005, 12:12 AM
The rule is that you can't close a window that you didn't open. Since PHP can't open browser windows, it can't close them either.

If Javascript opened a window then it can close it. If Javascript tries to close a window it didn't open then some browsers ask for permission while others just ignore the request since it is not valid.