How to change browser focus from one tab to another

前端 未结 6 635
暗喜
暗喜 2020-11-28 14:01

I have a JavaScript chat client running in one browser tab (call it tab A). Now when a message arrives the user might be on another browser tab (call it tab B). I\'m looking

6条回答
  •  野性不改
    2020-11-28 14:40

    It is not possible - due to security concerns.

    unless by "tab" you mean a window and a popup window that (due to browser preferences) opened up in a new tab. If this is the case, then yes you can.

    //focus opener... from popup
    window.opener.focus();
    
    //focus popup... from opener
    yourPopupName.focus(); 
    

提交回复
热议问题