在Firefox中单击桌面通知时如何将焦点集中到选项卡上? [英] How to get focus to the tab when a desktop notification is clicked in Firefox?

查看:103
本文介绍了在Firefox中单击桌面通知时如何将焦点集中到选项卡上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个网站中实施桌面通知,当新消息到达时显示通知。当用户点击通知时,我希望打开网站的浏览器标签获得焦点。我可以通过以下代码在Chrome中运行:

  var n = new Notification('Title',{
'body':'Sample content。'
});

n.onclick = function(e){
window.focus();
};

但不幸的是,这在Firefox中不起作用。 :(有谁能告诉我我在这里失踪了什么?我在Chrome 31和Firefox 26中测试
$ b $ p感谢。

默认是禁用的。有趣的是Chrome浏览器窗口被禁用,除了响应用户操作(如点击)这就是为什么点击通知在Chrome中工作的唯一原因。


I am implementing desktop notifications in a website which displays notifications when new messages arrive. I want the browser tab in which the site is open to get focus when the user clicks on the notification & I could get this worked in Chrome with the following code:

var n = new Notification('Title', {
    'body': 'Sample content.'
});

n.onclick = function (e) {
    window.focus();
};

But unfortunately, this doesn't work in Firefox. :( Could anyone tell me what I am missing here? I am testing in Chrome 31 & Firefox 26

Thanks.

解决方案

In Firefox focusing window from JS is disabled due to security reasons. You have to switch flag dom.disable_window_flip to false in about:config. But by default it is disabled. The interesting moment is that in Chrome focusing window is disabled too except in response to user actions (such as click) and that's only reason why clicking on notifications works in Chrome.

这篇关于在Firefox中单击桌面通知时如何将焦点集中到选项卡上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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