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 7 of 7
  1. #1
    Saz
    Saz is offline
    Regular Coder
    Join Date
    Jun 2005
    Posts
    277
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question Code for closing an internet page

    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.

    Saz.

  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    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.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #4
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #5
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 ...
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #6
    New Coder
    Join Date
    Aug 2005
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you want to close the window based on a test in PHP, you could try:

    PHP Code:
    <?php
     $onload 
    "";
     if (
    myTestSucceeds) {
         
    $onload " onload='window.close();'";
     }
    ?>
    <html>
    <head>
    <title></title>
    </head>
    <body<?php if ($onload) { ?><?=$onload?><?php ?>>
     page content
    </body>
    </html>
    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.

    C.

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,603
    Thanks
    0
    Thanked 645 Times in 635 Posts
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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