PHP5: Want exit button to close browser

I can capture that the user “clicked” ‘Exit’ in my PHP Controller.php (i.e. form action=“/controller.php”), but I cannot come up with a function or command that will close the browser. The best I’ve been able to do is EXIT() which at least clears the window – but hardly user friendly.

Changing the (xhtml) input type from “submit” to “button” and adding javascript close() as an onClick event doesn’t do the trick either – apparently because I build the page in PHP5.

I expect I’m missing the obvious. Any thoughts?

try window


PHP is server-side. What you’re looking for is client-side. Use javascript.

Tsalagi beat me to it.

Just so I’m clear on your desired flow… You want to submit the form then automatically close the browser?

Off Topic:

Waves at Yader, nice to see you here. :wink:

Thanks guys –
@tsalagi, @YadarBH … I tried the javascript and it didn’t work (see the original post). The javascript folks tell me it has something to do with the window generated through PHP5.

@Anthony Sterling; Congratulations on your award. It’s wonderful see your contributions honored.

Here’s the relevant section of the PHP-generated XHTML (. is for formatting in this reply)

<div id=“ContentWrapper”>
.<div id=“ContentColumn”>
…<div class=“Liner”>
…<h2>Select Test Application Name</h2>
…<p>Please type in Application – or choose ‘Add App’ button</p>
…<form method=“post” action=“./controller.php”>
…<legend>Question / Task</legend>
…<label for=“application”>Application</label>
…<input type=“text” name=“application” id=“application” value=“” />
…<fieldset id=“actionbox”>
…<input type=“submit” value=“Select” name=“Select” />
<input type=“submit” value=“Exit” name=“Exit” />
…<input type=“hidden” name=“switchbase” id=“switchbase” value=“” />
…<input type=“hidden” name=“appkey” id=“appkey” value=“” />
…<input type=“hidden” name=“qkey” id=“qkey” value=“” />
…</div><!-- end Liner –>
.</div><!-- end ContentColumn –>
</div><!-- end ContentWrapper –>

and here’s the start of the application.php (again, . just for format)

// Purpose: Control Processing
// Requires: $_POST global variable
// crucial: $_POST[“switchbase”]
// Invokes: Appropriate module(s)
// Returns: Form
// On error: Passes error message to display module

if(!is_null($_POST[“Exit”])) {
…$formType = new fitb_FormType(“Select”); // initialize data structure
…$formType->BuildFromPost(); // populate data structure from $_POST in case of early return

JavaScript can only close browser windows that were opened using JavaScript. If it wasn’t opened using a JavaScript call then JavaScript can’t close it.

Isn’t it up to user whether they want to close the browser or not? Why would you even want to create such a “feature” anyway?

I am not making myself clear. My Fault.

I simply want the screen to disappear when the user clicks the exit button as if the user had clicked the “x” for the browser tab.

(If the user has other windows open in the same browser, let the system decide whih of those to enable).

You can’t do that.

You can only use JavaScript to do that if the window was opened using JavaScript. If the window wasn’t opened using JavaScript then the only way to close the window is using the browser built-in close window options. Except for windows opened by JavaScript there is no way of closing the window from within the web page (and even then that only applies while the page that was first loaded in the window is still displayed).

So to make it completely clear to you.

Unless the current window and web page were loaded from a JavaScript command there is no way for the web page to close the window.

I’ll be darned.

Thanks for your patience and feedback.

I was surprised with the JavaScript solution as I agree with the conclusion that this can not be done. Exiting software would have to be something done by said software.
it reminds me of When someone asked me if one could use php to control a machine’s hardware…

Why wouldn’t this work?
<a href=“javascript:window.close();”>Close Window</a>

The OP’s window would not have been generated by JS. :wink: