views:

33

answers:

1

There is a chat button, and when users click on that chat button a new window will be opened and both the users can chat

how can i know, whether chat window is still open or not, when any of the user logged out from the application ?

and give a message, "chat window still open" and close the chat window...

name of the chat window : chat<?=$user->username?>...

I'm tracking when user logout, and other tries to send a message....then i'm giving him a message and close that window

code to open a window

win = window.open('../chat/index.php?user=<?=$uname->username?>','chatApp<?=$uname->username?>','width=400, height=500');

i need to close the chat window when users click on logout ? is this code right ?

echo "<script>win.close();</script>";

Thanks for the kind help

A: 

As long as the window that opens the pop up windows does not get reset [closed, refreshed, posted back] and kill the window object you can do something like the following to maintain the windows created.

  var winPop = {}

  function openPop( username, url ){
      if(winPop[username]){
          closePop(username);
      }
      winPop[username] = window.open( url );
  }

  function closePop( username ){
      if(winPop[username] && !winPop[username].closed){
          winPop[username].close();
          winPop[username] = null;
      }
  }

  function killAllPop(){
      for(var win in winPop){
          closePop(win);
      }
  }

If the window that opens it looses the window object you are out of luck with the parent closing it unless you do the clean up on onunload or onbeforeunload.

epascarello
this is not working ?
luvboy