简体   繁体   English

如何知道窗口是否打开-PHP / Javascript?

[英]how to know whether window is opened - PHP/Javascript?

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?> ... 聊天窗口的名称: 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>";

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. 如果打开的窗口失去了窗口对象,那么您会很不走运,而父级会关闭它,除非您在onunload或onbeforeunload上进行清理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM