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.
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)
and here’s the start of the application.php (again, . just for format)
<?php
// 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”])) {
…die();
…}
…$formType = new fitb_FormType(“Select”); // initialize data structure
…$formType->BuildFromPost(); // populate data structure from $_POST in case of early return
<snip>
JavaScript can only close browser windows that were opened using JavaScript. If it wasn’t opened using a JavaScript window.open() call then JavaScript can’t close it.
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 window.open() command there is no way for the web page to close the window.
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…