Hi,

I have a PHP script that outputs some HTML as feedback on what it is doing. Once the file runs, anyone know how I can make it close automatically?

I have this in the page after the PHP:

<script language="Javascript">
javascript:window.close();
</script>

But this gives a popup which has to be clicked before it closes. This script will be running automatially every 15 minutes so i need the browser to just close on its own.

Thanks in advance,
Martin

    Well - from the looks of it, this is more a Javascript question than anything else...

    HOWEVER, let me just get this right before I continue - you are running a script, and you want to close the browser window as soon as it has finished?

    If so - then the first thing to note is the syntax for your Javascript... it should read like this...

    <script language="Javascript">
    <!--
        window.close();
    //-->
    </script>
    

    The comment type tags around the window.close just hide the code from any browsers which don't run JS (very few now I grant you).

    The problem you will probably experience with this, is that unless Javascript was responsible for opening the window (i.e. via window.open()😉 you will not be able to close the current window without a popup alert warning the user that JS is trying to close the window. This is an inherent security procedure to stop JS just closing all the windows in an explorer process, and as such it is not possible to circumnavigate this (unless you use signed code which must be marked as trusted by the client computer).

    Anyhow - hope this helps

      Hi,

      thanks for the reply.

      That sort of presents a problem.....is there a PHP function that can close a window? I need this to be automatic so if it is waiting on user confirmation then this wouldnt work out.

      Any ideas on a workaround or something?

      Martin

        Well, no. PHP runs on the server and doesn't know anything about "windows", "toolbars", "frames" and all the other bits and bobs of the modern graphical web browser experience - after all, many (most) of the http clients out there don't have any of those. All it knows about the client is that this here http request has come in with a buncha headers from this IP. Répondez s'il vous plaît.

        What the client does as a result of the response is entirely the responsibility of the client. PHP doesn't know, doesn't care, and doesn't have any control.

        What you're asking for is something that happens on the client's end of the connection, not the server's; refer back to bobthedog's post for how to go about doing that.

          Write a Reply...