如何将浏览器焦点从一个标签更改为另一个标签 [英] How to change browser focus from one tab to another

查看:171
本文介绍了如何将浏览器焦点从一个标签更改为另一个标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JavaScript聊天客户端运行在一个浏览器选项卡中(称为选项卡A)。现在当消息到达用户可能在另一个浏览器选项卡(称为选项卡B)。我正在寻找方法来改变焦点从标签B到我的聊天客户端(标签A),当这样的消息到达。



我找不到这样做的方法。由于安全考虑, 可能是可能的 / p>

除非tab指的是一个窗口和一个弹出窗口(由于浏览器首选项)在新选项卡中打开。如果是这样,那么你可以。

  //焦点开启者...从弹出
窗口。 opener.focus();

//聚焦弹出...从开瓶器
yourPopupName.focus();


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 for ways to change the focus from tab B to my chat client (tab A) when such a message arrives.

I could not find a way to do this.

解决方案

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(); 

这篇关于如何将浏览器焦点从一个标签更改为另一个标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆