Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question close current window?

    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.


    Jason

  • #2
    Regular Coder
    Join Date
    Feb 2003
    Location
    East Side/West Side
    Posts
    118
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

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

    Something like that...

  • #3
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    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.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #4
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, so I tried that code: I used
    <input type="submit" onClick="<? $close=1; ?>">

    And at the end of the script I put:

    PHP:

    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?

    Jason

  • #5
    New Coder
    Join Date
    Mar 2003
    Location
    Dublin, Ireland
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    Code:
    <script>setTimeout("self.close()",1000);</script>
    The part in red you can change to the milliseconds you want it to wait for.
    TopHostingDeals - The best place for the best deals!
    "It's nice to be important, but it's more important to be nice!"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •