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
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,383
    Thanks
    264
    Thanked 32 Times in 31 Posts

    cannot close popup

    I am having a heck of a time closing this popup window when i logoff the site.

    i open it by

    Code:
    shoutwindow = window.open("<?=$MY_LINK_ROOT?>/shoutbox/minichat.php", "shoutwindow", "location=0,status=0,scrollbars=0,menubar=0,resizable=0  width=300,height=310");
    when i click logoff the site i want the popup to close also

    here is the logoff php

    Code:
    session_start();
    
             //only for testing will remove this
    
        if(!shoutwindow.closed)  
    
          {  
    
             echo "window open";
                   self.close(); 
    
               
               //shoutwindow.close ();  // also tried both these didnt work
               //  window.close();
    
          }  
    
          else  
    
          {  
    
             echo "Window already closed";           
    
          }  
    
     
    
    
    mysql_close($link);
    unset($_SESSION['Sess_UserId']);
    
    // Unset all of the session variables.
    
    session_unset();
    
    // Finally, destroy the session.
    
    session_destroy();
    
    echo "<script> location.href='$MY_LINK_ROOT'</script>";
    
    exit;
    
    ?>

    what am i missing here lol ? thanks

    UPDATE: i just had an idea, can i mix a href and an onClick together so that both are executed like this (i never tried it before)

    Code:
    the reason i use self.close is because i heard that it always closes the child not the parent.
    
    <a href="logoff.php" onClick="self.close()" return:true;>Log Off</a>
    
    the return true will make it execute the href as well right?
    Last edited by durangod; 07-13-2011 at 04:27 AM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,508
    Thanks
    77
    Thanked 4,378 Times in 4,343 Posts
    Ummm...the close code has to be in *JAVASCRIPT*. You can't close windows from PHP code.

    But more than that, only the page that *OPENED* the window can close it [there are ways around this...they are a pain in the patootie], so clearly a subsequent PHP page can't close what a prior PHP page opened.

    (The reason for that latter restriction: You must have a JavaScript object reference to the other window. You get that by doing var w = window.open(....); so that later you can do w.close( ). But how do you pass that JavaScript object reference from one incarnation of a window to another??? The general answer: you don't. The hacky trick is that you *can* try to REOPEN the same window--by NAME--and if it's already open you get a reference to the already open window instead of opening another window. But what if the window isn't open? Now you have opened it when you didn't want to. Anyway... you sure can't do any of it from PHP code.)
    Last edited by Old Pedant; 07-13-2011 at 04:36 AM.

  • #3
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,383
    Thanks
    264
    Thanked 32 Times in 31 Posts
    ohhhhhhhh dang ok thanks bud appreciate that very much.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,508
    Thanks
    77
    Thanked 4,378 Times in 4,343 Posts
    See my added (edit) last paragraph in prior post, too.

    It *can* be done if you are careful.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,508
    Thanks
    77
    Thanked 4,378 Times in 4,343 Posts
    And self is just a synonym for "this window". So it closes whatever window calls it.

  • Users who have thanked Old Pedant for this post:

    durangod (07-13-2011)

  • #6
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,383
    Thanks
    264
    Thanked 32 Times in 31 Posts
    ok thanks it wont be that hard to convert it to javascript but its a trivial thing i wanted to do, just for asthetics is all. Prob not worth the time, without a session they cant post in the shout anyway so its just a dead popup sitting in their tray is all and they will eventually close it.

    thanks so much for the explaination for that.

    peace

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,508
    Thanks
    77
    Thanked 4,378 Times in 4,343 Posts
    You know, what you *could* do is have the popup monitor its own activity (I assume it is using AJAX?) and, if there isn't any activity for XX minutes, it could then turn itself off. Or ask the user if he/she wants it turned off.

  • Users who have thanked Old Pedant for this post:

    durangod (07-14-2011)


  •  

    Posting Permissions

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